Pato Navarro
Pato Navarro

Reputation: 300

Rabbitmq: Listening in MQTT

Here I will explain my desired used case:

How many messages I suppose to get? I expect 1, but I am getting 2 , and I am not sure I am testing right or if this is the expected beheavior.

Thanks for the help in advance

Upvotes: 1

Views: 5202

Answers (1)

IMSoP
IMSoP

Reputation: 97718

In AMQP, which RabbitMQ is engineered around, messages are always published to an exchange, routed according to routing keys and bindings and consumed from a queue.

In MQTT, messages are published to the broker, routed according to topics and consumed via a subscription.

The RabbitMQ MQTT plugin maps these concepts together:

  • The MQTT broker is emulated by a single exchange
  • The MQTT topic is used as a routing key
  • The MQTT subscription is a binding from that exchange to a queue
  • Finally, each MQTT client has a queue from which it can receive its subscribed messages

The key thing here is that these are just ordinary RabbitMQ exchanges and queues, used to emulate the MQTT model - messages can be routed by the broker to any queue, and messages from other brokers can be routed to the queue, and they don't need to relate to the topics you've defined in MQTT.

So if you manually route a message into the queue for a particular MQTT client, RabbitMQ will deliver it to the client along with other messages in that queue. The "topic" that the client is subscribed won't make any difference, because that is used only to set up the binding on the server.

Upvotes: 6

Related Questions