smrchy/rsmq

implementing remote redis message queue for push messages for two different cloud clients.

mayurgujrathi opened this issue · 4 comments

I want to implement remote redis message queue where remote client from AWS can produce message to this Queue and at other end client from Azure consume from same Queue and vice versa.

I want to implement remote redis message queue where remote client from AWS can produce message to this Queue and at other end client from Azure consume from same Queue and vice versa.

erdii commented

nice! You can definitely build this with rsmq.

RSMQ does not care on which cloud or where your servers are, as long you can reach a single redis server from all your locations.

I have implemented,

const express = require('express');
const app = express();

const RedisSMQ = require("rsmq");
const rsmq = new RedisSMQ( { host: "localhost", port: 6379, ns: "rsmq" } );

const bodyParser = require('body-parser');

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

app.get('/', function (req, res) {

const message = req.body.message;

rsmq.sendMessage({ qname: "myqueue", message: message}, function (err, resp) {

    if (err) {
        console.error(err)
        return
    }

    console.log("Message sent. ID:", resp);
});

});

const server = app.listen(8081, function () {
const host = '10.235.5.47';
const port = server.address().port;
console.log(Example app listening at http://${host}:${port});
})

But got confused how this message in queue is consumed on different cloud. What steps do I need to follow.

erdii commented

Well... you need a redis server that can be reached from both sides. Something like https://aws.amazon.com/elasticache/redis/ or your own self-hosted (and secured!) thing.

Then you connect both rsmq-clients to the same redis-server and on the receiving side you employ this code:

rsmq.receiveMessage({ qname: "myqueue" }, function (err, resp) {
	if (err) {
		console.error(err)
		return
	}

	if (resp.id) {
		console.log("Message received.", resp)
	} else {
		console.log("No messages for me...")
	}
});