问题描述
我正在尝试从我的 Android 应用程序连接到一个名为消息"的队列.
I am trying to connect from my Android app to one queue called "messages".
生产者(AMQP协议下的一个网络服务)已经连接,可以通过RabbitMQ管理面板查看.
The producer (one webservices under AMQP protocol) is already connected, it can be check through RabbitMQ admin panel.
要从我的 Android 设备连接,我是这样编码的.
To connect from my Android device I am coding like this.
private void connect() throws Exception {
this.sampleClient = new MqttClient(this.broker, this.clientId);
MqttConnectOptions connOpts = new MqttConnectOptions();
connOpts.setUserName("user");
connOpts.setPassword("user".toCharArray());
/*connOpts.setConnectionTimeout(60 * 10);
connOpts.setKeepAliveInterval(60 * 5);*/
connOpts.setCleanSession(true);
this.sampleClient.connect(connOpts);
this.sampleClient.setCallback(this);
this.sampleClient.subscribe("messages");
if(!this.sampleClient.isConnected()){
System.out.println("Not Connected");
return;
}
System.out.println("Connected");
}
我尝试过使用amq.topic"、amq.topic.*"、amq.topic.messages"等...但是当我查看 RabbitMQ 队列部分时,消息"有 0 个消费者,并自动设置了一个名为mqtt-subscription-Sampleqos1"的新队列.
I have tried with "amq.topic", "amq.topic.*", "amq.topic.messages", etc... But when I look in the RabbitMQ queue section "messages" is with 0 consumers, and have been set one new queue called "mqtt-subscription-Sampleqos1" automatically.
发生了什么事?如何订阅消息"队列?
What's happening? How can I susbscribe to "messages" queue?
推荐答案
这个问题有两个重点.
根据 RabbitMQ MQTT 文档:http://www.rabbitmq.com/mqtt.html一个>
According with the RabbitMQ MQTT documentation: http://www.rabbitmq.com/mqtt.html
首先,每个队列都被mqtt-plugin自动绑定到amq.topic交换.
Firstly, every queues are bound automatically to amq.topic exchange by the mqtt-plugin.
其次,每个订阅者都有自己的队列,如下所示,mqtt-subscription-{cliend_id}{qosX}(其中 X 是订阅的 qos 级别)
Secondly, every subscriber has his own queue which look like this, mqtt-subscription-{cliend_id}{qosX} (where X is the qos level of the subscription)
因此,生产者必须将消息发布到amq.topic"交换,amq.topic.."路由键,接收者必须订阅amq.topic.."路由键.
Therefore, producer must to publish the message to "amq.topic" exchange, and "amq.topic.." routing-key, and receiver must to subscribe to "amq.topic.." routing-key.
这篇关于如何使用 MQTT Paho 订阅 RabbitMQ 队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!