Is it possible to connect MQTT client to RabbitMQ having Node.JS as intermediate gateway?

882 views
Skip to first unread message

Pritam Upadhyay

unread,
Jun 2, 2015, 5:35:21 AM6/2/15
to mq...@googlegroups.com

This is what I want to do:

I want to connect my client using MQTT to Node.JS server and then from there(Node.JS Server) I want to handle all pub/sub. When client publishes any message, it will go to Node.JS server and from there it will be sent to RabbitMQ and reverse for the subscriber.

Flow is like :-

MQTT -> Node.JS -> RabbitMQ.

This is what i found on mosca home page. I added few lines for RabbitMQ connections. 

 Server.JS

var mosca = require('mosca')
var pubsubsettings = {
    type: 'mqtt',
    json: false,
    mqtt: require('mqtt'),
    host: '127.0.0.1',
    port: 1883
};
var settings = {
    port: 1883,
    backend: pubsubsettings  
};

var server = new mosca.Server(settings);
server.on('ready', setup);


function setup() {
    console.log('Mosca server is up and running')
}


server.on('clientConnected', function (client) {
    console.log('client connected', client.id);
});


server.on('published', function (packet, client) {
    console.log('Published : ', packet.payload);
});


server.on('subscribed', function (topic, client) {
    console.log('subscribed : ', topic);
});

// fired when a client subscribes to a topic
server.on('unsubscribed', function (topic, client) {
    console.log('unsubscribed : ', topic);
});

server.on('clientDisconnecting', function (client) {
    console.log('clientDisconnecting : ', client.id);
});


server.on('clientDisconnected', function (client) {
    console.log('clientDisconnected : ', client.id);
});
Now I want to create a client that can connect to this Node.JS server. But I am not able to figure out the way to connect. 



Paul Fremantle

unread,
Jun 2, 2015, 6:47:05 AM6/2/15
to mq...@googlegroups.com

Rabbit supports MQTT directly.
https://www.rabbitmq.com/mqtt.html

Paul

--
To learn more about MQTT please visit http://mqtt.org
---
You received this message because you are subscribed to the Google Groups "MQTT" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mqtt+uns...@googlegroups.com.
To post to this group, send email to mq...@googlegroups.com.
Visit this group at http://groups.google.com/group/mqtt.
For more options, visit https://groups.google.com/d/optout.

Pritam Upadhyay

unread,
Jun 2, 2015, 6:50:51 AM6/2/15
to mq...@googlegroups.com, paul.fr...@port.ac.uk
Yes i know. But my requirement is to use Node.js as intermediate gateway. Is it possible to follow this flow?

Paul Fremantle

unread,
Jun 2, 2015, 2:15:24 PM6/2/15
to Pritam Upadhyay, mq...@googlegroups.com
Pritam

Its not clear from the code how you are connecting to Rabbit. As for the client connection, any normal MQTT client should be able to connect to Mosca if it is running a MQTT broker on port 1883.

A simple node.js client for MQTT looks like this:
var mqtt = require('mqtt')
client = mqtt.createClient(1883, 'localhost');
client.publish('/topic', 'message'l);


If you want a generic answer if what you are doing is possible, the answer is yes, of course. If you want specific help with Mosca you should contact Matteo or the Mosca community. 

Paul
--
Paul Fremantle
Part-time PhD student - School of Computing
twitter: pzfreo / skype: paulfremantle / blog: http://pzf.fremantle.org
Co-Founder, WSO2
Apache Member and Committer
07740 199 729

Pritam Upadhyay

unread,
Jun 8, 2015, 1:57:42 AM6/8/15
to mq...@googlegroups.com, upadhya...@gmail.com
I have implemented the upper mention parts.
Further more, I want to know that. Can I publish any message from mosca server to mqtt.js client?

[Case for Publishing Message from mosca server to mqtt.js client - Assume  I am giving limited number of messages to be published, When that limit it reached, A custom message 'Limit is reached' should be published to publisher and subscriber both. For this , i need to send message from the server. Can you help me with this?]

Hans Jespersen

unread,
Jun 8, 2015, 4:29:17 PM6/8/15
to mq...@googlegroups.com
Your use of the terms client and server are very confusing. 
Both publishing and subscribing are always from the client. A client can publish to the server (mqtt broker) or a client can subscribe to messages from the server (mqtt broker).

-hans

Pritam Upadhyay

unread,
Jun 9, 2015, 8:29:12 AM6/9/15
to mq...@googlegroups.com
Hi Hans,

Yes I know  - > Both publishing and subscribing are always from the client. A client can publish to the server (mqtt broker) or a client can subscribe to messages from the server (mqtt broker).
But my requirement is to send message back to client from broker. However I implemented it.

Thanks for your reply.
Pritam Upadhyay.

Hans Jespersen

unread,
Jun 9, 2015, 9:07:02 PM6/9/15
to mq...@googlegroups.com
Then have your broker also act as an mqtt client and publish to a special topic for your own special use case.

-hans

Pritam Upadhyay

unread,
Jun 10, 2015, 12:17:44 AM6/10/15
to mq...@googlegroups.com
Yes sir. Exactly.
Reply all
Reply to author
Forward
0 new messages