我正在尝试使Aedes用作MQTT代理和Websocket服务器。根据该文档:https://github.com/moscajs/aedes/blob/master/docs/Examples.md 我本该理解的。理想情况下,我希望监听器启动一个websocket客户端或mqtt客户端。
是否可以做类似的事情:
server.broadcast('foo / bar',{data:''})
,所有客户端,websockets和mqtt都收到消息?该文档不是很清楚,我非常惊讶使用了websocket-stream。 lvl很低吧?
此处是一些服务器端代码:
const port = 1883
const aedes = require('aedes')({
persistence: mongoPersistence({
url: 'mongodb://127.0.0.1/aedes-test',
// Optional ttl settings
ttl: {
packets: 300, // Number of seconds
subscriptions: 300
}
}),
authenticate: (client, username, password, callback) => {
},
authorizePublish: (client, packet, callback) => {
},
authorizeSubscribe: (client, packet, callback) => {
}
});
//const server = require('net').createServer(aedes.handle);
const httpServer = require('http').createServer()
const ws = require('websocket-stream')
ws.createServer({ server: httpServer }, aedes.handle)
httpServer.listen(port, function () {
Logger.debug('Aedes listening on port: ' + port)
aedes.publish({ topic: 'aedes/hello', payload: "I'm broker " + aedes.id })
});
答案 0 :(得分:1)
应该只用相同的Java.lang.NullPointerException: system must not be null!
[info] at java.base/java.util.Objects.requireNonNull(Objects.java:246)
[info] at akka.actor.ExtensionId.apply(Extension.scala:78)
[info] at akka.actor.ExtensionId.apply$(Extension.scala:77)
[info] at akka.testkit.TestKitExtension$.apply(TestKitExtension.scala:14)
[info] at akka.testkit.TestKitBase.$init$(TestKit.scala:161)
[info] at akka.testkit.TestKit.<init>(TestKit.scala:928)
[info] at MyTest.<init>(MyTest.scala:40)
[info] at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
[info] at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
[info] at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
对象启动两个服务器,如下所示:
aedes