[rabbitmq-discuss] Cannot get MQTT->AMQP to work

Dejan Glozic dejan.glozic at gmail.com
Thu Apr 17 03:05:01 BST 2014


Just realized the example is not clear - the value of 'queueName' on the 
MQTT side is 'builds' - the same as the value for the 'routingKey' on the 
AMQP side used for channel.queueBind.

Dejan

On Wednesday, April 16, 2014 6:29:41 PM UTC-4, Dejan Glozic wrote:
>
> I am banging my head on my desk the whole afternoon trying to figure this 
> out. I am trying to publish a message into an MQTT topic using Eclipse MQTT 
> Paho client, and receive it using RabbitMQ AMQP Java client.
>
> I am using RabbitMQ for Windows, version 3.2.4.
>
> From what I was reading, MQTT plug-in will publish into the default 
> 'amq.topic' exchange, and I can bind a queue to that exchange and start 
> listening.
>
> When I publish a message into the exchange using AMQP client, the AMQP 
> client on the receiving end will get it.
>
> When I publish a message using MQTT client, another MQTT client on the 
> receiving end will get it.
>
> But for the love of God I cannot get the cross-protocol to work.
>
> Here is the MQTT client that publishes:
>
>
> MqttClient client;
>
> *try* {
>
>     client = *new* MqttClient("tcp://"+host+":1883", "pahomqttpublish1");
>
>     client.connect();
>
>     MqttMessage message = *new* MqttMessage(messageText.getBytes());
>
>     client.publish(queueName, message);
>
>     System.*out*.println(" [x] Sent to MQTT topic '" +queueName+"': "+ 
> message + "'"); 
>
>     client.disconnect(); 
>
> } *catch* (MqttException e) {
>
>     // *TODO* Auto-generated catch block
>
>     e.printStackTrace();
>
> }
>
>
> And here is the AMQP client that is supposed to receive it:
>
> public static final String QUEUE_NAME="workerQueue";
>
> *public* *static* *void* main(String[] args) *throws* IOException, 
> InterruptedException {
>
>    ConnectionFactory factory = *new* ConnectionFactory();
>
>    factory.setHost("localhost");
>
>    Connection connection = factory.newConnection();
>
>    Channel channel = connection.createChannel();
>
>    channel.queueDeclare(QUEUE_NAME, *true*, *false*, *false*, *null*);
>
>    channel.queueBind(QUEUE_NAME, "amq.topic", "builds");
>
>    System.*out*.println(" [*] Waiting for messages. To exit press CTRL+C"
> );
>
>
>    QueueingConsumer consumer = *new* QueueingConsumer(channel);
>
>    channel.basicConsume(QUEUE_NAME, *true*, consumer);
>
> *   while* (*true*) {
>
>       QueueingConsumer.Delivery delivery = consumer.nextDelivery();
>
>       String message = *new* String(delivery.getBody());
>
>       String routingKey = delivery.getEnvelope().getRoutingKey();
>
>       System.*out*.println(" [x] Received '" + routingKey + "':'" + 
> message + "'");
>
>    }
>
> }
>
>
> The client above will receive the message when published into "amq.topic" 
> exchange by another AMQP client.
>
> Anything stupid and obvious I am missing?
>
> Dejan
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20140416/e9eab122/attachment.html>


More information about the rabbitmq-discuss mailing list