Mosca 给出了这个错误:
TypeError: Client is not a constructor
at new KafkaAscoltatore (/home/x/Desktop/broker/node_modules/mosca/node_modules/ascoltatori/lib/kafka_ascoltatore.js:59:26)
at Object.build (/home/x/Desktop/broker/node_modules/mosca/node_modules/ascoltatori/lib/ascoltatori.js:77:12)
at /home/x/Desktop/broker/node_modules/mosca/lib/server.js:181:40
at makeCall (/home/x/Desktop/broker/node_modules/fastseries/series.js:117:7)
at ResultsHolder.release (/home/x/Desktop/broker/node_modules/fastseries/series.js:96:9)
at series (/home/x/Desktop/broker/node_modules/fastseries/series.js:39:14)
at Object.series (/home/x/Desktop/broker/node_modules/steed/steed.js:90:7)
at new Server (/home/x/Desktop/broker/node_modules/mosca/lib/server.js:171:9)
at Object.<anonymous> (/home/x/Desktop/broker/broker.js:118:14)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
at startup (internal/bootstrap/node.js:266:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:596:3)
环境
- 节点版本:v10.9.0
- Kafka节点版本:最新
- Mosca 版本:最新
我试过的
我打开/home/x/Desktop/broker/node_modules/mosca/node_modules/ascoltatori/lib/kafka_ascoltatore.js
并查看下面的行后发现问题与 kafka-node 版本有关:
this._opts.kafka = this._opts.kafka || require("kafka-node");
当我删除this._opts.kafka
时,它开始正常工作。然后我打印了两个我发现新版本中没有客户端构造函数。这是我的打印结果:
this._opts.kafka (kafka-node v4.0.1 latest)
返回没有客户端的 HighLevelProducer,另一方面 require("kafka-node") (v0.5.9) 返回 HighLevelConsumer。
代码:
var backend = {
type: "kafka",
kafka: require('kafka-node'),
json: false,
connectionString: "IP:2181",
defaultEncoding: "utf8",
};
var moscaSettings = {
interfaces: [
{ type: "mqtt", port: PORT }
],
id: "mosca",
stats: false,
publishNewClient: false,
publishClientDisconnect: false,
publishSubscriptions: false,
backend: backend,
};
var server = new mosca.Server(moscaSettings); // Error pops here
如上所述,我可以让 Kafka 与旧版本一起使用,但我认为这只是一个快速修复,所以我希望有人能引导我找到正确的解决方案。