From MQTT to AMQP

823 views
Skip to first unread message

Eric Fernandez Merchan

unread,
Jul 14, 2015, 1:50:23 PM7/14/15
to rabbitm...@googlegroups.com
So I want to have the following set up :

Android APP -> (MQTT)  -> rabbitmq -> (AMQP) -> Desktop APP

Every android user has its own ID that is already known by the desktop app so they can directly subscribe to that userID queue.So, I have some questions:

1.-
Every message, no matter what topic is used, is published into the default exchange " amq.topic  " right ?

2.-
What is the routing key pattern that rabbitmq uses to create the queues so every user can connect and consume ?

3.- How can I know the names of the automatically created queues so I can consume messages from them by knowing the userID, topic and QoS ? They also follow a pattern ?

Thanks in advance




Michael Klishin

unread,
Jul 14, 2015, 1:55:11 PM7/14/15
to Eric Fernandez Merchan, rabbitm...@googlegroups.com
 On 14 Jul 2015 at 20:50:26, Eric Fernandez Merchan (mercha...@gmail.com) wrote:
> Every android user has its own ID that is already known by the
> desktop app so they can directly subscribe to that userID queue.So,
> I have some questions:
>
> 1.- Every message, no matter what topic is used, is published
> into the default exchange " amq.topic " right ?

With MQTT plugin with stock settings, yes. You can configure what
exchange is used, as long as its type is “topic”.

> 2.- What is the routing key pattern that rabbitmq uses to create
> the queues so every user can connect and consume ?

Every MQTT consumer specifies a topic it consumes from. This is what
RabbitMQ uses, translating MQTT wildcard patterns into AMQP 0-9-1.

> 3.- How can I know the names of the automatically created queues
> so I can consume messages from them by knowing the userID, topic
> and QoS ? They also follow a pattern ?

The names are prefixed with mqtt and include client ID and QoS level used.
They are not particularly sophisticated: add a few MQTT consumers and see
queue names in the management UI or via `rabbitmqctl list_queues`.
--
MK

Staff Software Engineer, Pivotal/RabbitMQ


Michael Klishin

unread,
Jul 14, 2015, 2:29:56 PM7/14/15
to Eric Fernandez Merchan, rabbitm...@googlegroups.com
 On 14 Jul 2015 at 20:55:08, Michael Klishin (mkli...@pivotal.io) wrote:
> > 1.- Every message, no matter what topic is used, is published
> > into the default exchange " amq.topic " right ?
>
> With MQTT plugin with stock settings, yes. You can configure
> what
> exchange is used, as long as its type is “topic”.
>
> > 2.- What is the routing key pattern that rabbitmq uses to create
> > the queues so every user can connect and consume ?
>
> Every MQTT consumer specifies a topic it consumes from. This
> is what
> RabbitMQ uses, translating MQTT wildcard patterns into AMQP
> 0-9-1.

Also, I should point out that as long as your publishers and consumers
agree on topics, in many cases shouldn’t matter what the actual queue names are.

Eric Fernandez Merchan

unread,
Jul 14, 2015, 4:26:35 PM7/14/15
to rabbitm...@googlegroups.com, mercha...@gmail.com
So, as I just want to send direct messages between an android app and a desktop app that got the same useID, I can:

a) Make publishers send messages with the same topic and then have to guess and code somehow the queue name they are consuming from:

 channel.queueDeclare(QUEUE_NAME, ...)
 channel
.basicConsume(QUEUE_NAME, true, consumer);

b) Make them publish with a custom topic (the userID for example), so the comsumers have just to get the queue name like this ?
      
channel.exchangeDeclare(EXCHANGE_NAME (USERID in my case), "topic");
String queueName = channel.queueDeclare().getQueue();
channel
.queueBind(queueName, EXCHANGE_NAME, "");



Thanks for helping

Michael Klishin

unread,
Jul 14, 2015, 5:31:56 PM7/14/15
to Eric Fernandez Merchan, rabbitm...@googlegroups.com
On 14 Jul 2015 at 23:26:39, Eric Fernandez Merchan (mercha...@gmail.com) wrote:
> So, as I just want to send direct messages between an android
> app and a desktop app that got the same useID, I can:
>
> a) Make publishers send messages with the same topic and then
> have to guess and code somehow the queue name they are consuming
> from:
>
> channel.queueDeclare(QUEUE_NAME, ...)
> channel.basicConsume(QUEUE_NAME, true, consumer);
>
> b) Make them publish with a custom topic (the userID for example),
> so the comsumers have just to get the queue name like this ?
> channel.exchangeDeclare(EXCHANGE_NAME (USERID in my case),
> "topic");
> String queueName = channel.queueDeclare().getQueue();
> channel.queueBind(queueName, EXCHANGE_NAME, "”);

Make them publish to a topic such as /devices/${DEVICE_ID}.

In your (AMQP 0-9-1) consumer, declare a queue (can be server-named),
bind it to amq.topic (topic exchange used by MQTT plugin unless configured
otherwise) with routing key = "devices.*” (for example) and consume from that
queue.

There is NO need to use separate exchange, one exchange per device, etc. You already
know what exchange is used and what routing key are used by your Android publisher.
Just consume that data.

To respond to Android clients, take the idea from Tutorial 6 [1]
and possibly adjust it a bit to your needs (chances are, there will be next to no adjustment).

1. http://www.rabbitmq.com/getstarted.html

Eric Fernandez Merchan

unread,
Jul 15, 2015, 2:09:18 PM7/15/15
to rabbitm...@googlegroups.com, mercha...@gmail.com
Ok, I got it all clear but one thing.

Does rabbitmq actually creates automatically a queue when a MQTT message arrives so the message is not lost ?

Because if there is not such a queue and if I got my consumer down, then there is no queue created binded to that exchange and the message would be lost in the exchange right ?

If that automatic queue it's created, when the consumer creates another to get the messages from that exchange , wont I end up having 2 queues or more for each consumer ?

Michael Klishin

unread,
Jul 15, 2015, 3:11:12 PM7/15/15
to Eric Fernandez Merchan, rabbitm...@googlegroups.com
A queue is declared when client subscribes, one per (client id, qos) pair.

MK
Reply all
Reply to author
Forward
0 new messages