Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Managing offline messages #94

Open
m-frachet opened this issue Mar 4, 2015 · 1 comment
Open

Managing offline messages #94

m-frachet opened this issue Mar 4, 2015 · 1 comment

Comments

@m-frachet
Copy link

I didn't know where to ask this, and cant find it in the README or exemple, so I try there.

Is it possible, using RabbitJS, to manage offline messages when a user disconnects ?

The aim is to use it for Android Application and SocketIO even if there are network loss.

Can you tell me how should I do that ?

Here's my code :

var context = require('rabbit.js').createContext();
var app = require('express')();
var server = require('http').Server(app);
var io = require('socket.io')(server);

app.get('/', function (req, res) {
res.sendfile(__dirname + '/index.html');
});

server.listen(8888);

io.sockets.on('connection', function (socket) {
var pub = context.socket('PUB');
var sub = context.socket('SUB');
sub.setEncoding('utf8');
pub.connect('q');
sub.connect('q');

socket.on('message', function (msg) {
    pub.write(msg, 'utf8');
});

sub.on('data', function (msg) {
    socket.emit('news', msg);
});

/* On ferme les streams lorsqu'on se deco */
socket.on('disconnect', function () {
    pub.close();
    sub.close();
});

});

@squaremo
Copy link
Owner

This is not really encouraged, by design -- PUB/SUB sockets are meant to only collect messages while your application is running.

You may find it easier to encode what you want in amqplib (squaremo/amqp.node), which has full control over the lifetime of exchanges and queues and so on, at the cost of having to do things at a "lower level".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants