【发布时间】:2019-07-15 14:04:18
【问题描述】:
我试图在网上寻找示例或解决方案,但没有运气..基本上我有 RabbitMQ 驻留在 C# 应用程序上以这种方式发送消息..
var factory = new ConnectionFactory() { HostName = "localhost", Port = 5672 };
using (var connection = factory.CreateConnection())
using (var channel = connection.CreateModel())
{
string message = "Hello World!";
var body = Encoding.UTF8.GetBytes(message);
channel.BasicPublish(exchange: "amqp.topic",
routingKey: "TestMQTT",
basicProperties: null,
body: body);
Console.WriteLine(" [x] Sent {0}", message);
}
和一个简单的 Javascript 客户端,带有 MQTT Paho js 库(无 nodejs),我试图以这种方式使用来自 AMQP 的消息: p>
var wsbroker = "localhost"; // mqtt websocket enabled broker
var wsport = 15675; // port for above
var client = new Paho.MQTT.Client(wsbroker, wsport, "/ws",
"myclientid_" + parseInt(Math.random() * 100, 10));
client.onConnect = function (responseObject){
client.subscribe("TestMQTT");
}
client.onConnectionLost = function (responseObject) {
debug("CONNECTION LOST - " + responseObject.errorMessage);
};
client.onMessageArrived = function (message) {
debug("RECEIVE ON " + message.destinationName + " PAYLOAD " + message.payloadString);
print_first(message.payloadString);
};
到目前为止,我还没有收到任何东西,有人可以为我指出正确的方向,可能还有一些示例代码吗?
【问题讨论】: