首页 > 解决方案 > 如何将相同的消息广播到 Mosca 中的多个接口

问题描述

我有 2 个接口,一个 mqtt 和一个用于 websocket。我注意到如果我有后端,mqtt 不会路由到 websocket。

我创建了 mosca 服务器,如下所示:

server = new mosca.Server(
  {
    interfaces: 
    [
      { type: "mqtt", port: 1883 },
      {
        type: "mqtts",
        port: 8443,
        credentials: { keyPath: SECURE_KEY, certPath: SECURE_CERT }
      },
      { type: "http", port: 4000, bundle: true }
    ],
    onQoS2publish: "noack", 
    logger: { name: 'MoscaServer', level: 'debug' },
    backend: {
      type: "mqtt",
      json: false,
      mqtt: require("mqtt"),
      key: filesys.readFileSync(__dirname + "/certs/private.key"),
      cert: filesys.readFileSync(__dirname + "/certs/cert.pem"),
      ca: filesys.readFileSync(__dirname + "/certs/rootCA.cer"),
      clientId: "randomClientId",
      port: 8883,
      host: "<aws IOT endpoint>.iot.<aws region>.amazonaws.com",
      rejectUnauthorized: false,
      protocol: "mqtts"
    },
  }
);

我需要做什么才能在所有 3:mqtt、websocket 和后端之间进行路由?

谢谢!

标签: node.jsmqttiotaws-iotmosca

解决方案


推荐阅读