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

Work Queue like in rabbitmq? #118

Open
Dexus opened this issue Sep 13, 2015 · 3 comments
Open

Work Queue like in rabbitmq? #118

Dexus opened this issue Sep 13, 2015 · 3 comments
Labels

Comments

@Dexus
Copy link

Dexus commented Sep 13, 2015

Is there a way to use nanomsg as Work Queue like https://www.rabbitmq.com/tutorials/tutorial-two-javascript.html?

@reqshark
Copy link
Collaborator

the work queue backpressure mechanism isn't perfect, but you can use node streams pause() and resume() methods on PUSH/PULL, a.k.a. pipeline. If you need to distribute precise load balancing tasks among stateless workers, then REQ/REP might be better.

Anyway, if you want to checkout PUSH/PULL, create two files:

  • push.js
  • pull.js

it's best to get the workers ready first. to get them going, run the file below a few times. open some new tabs on your terminal and execute this in each one:

// pull.js
// a worker process
var nano   = require('nanomsg');
var pull   = nano.socket('pull');
pull.connect('tcp://127.0.0.1:7789');
pull.pipe(process.stdout);
console.log('waiting...');

then open one last tab and run the push socket like:

// push.js
// source of work
var work   = 0;
var nano   = require('nanomsg');
var push   = nano.socket('push');
push.bind('tcp://127.0.0.1:7789');

setInterval( send, 100 );
function send(){ push.send('counted work:' + ++work + '\n'); }

make sure to switch back to the other tabs and kill some of the worker processes. or bring them back online too if you want, just note the change in rate of consumption.

http://nanomsg.org/v0.8/nn_pipeline.7.html

http://nanomsg.org/v0.8/nn_reqrep.7.html

@thelinuxlich
Copy link

One thing that puzzles me is when you think about adding persistence(like Redis) with nanomsg...if every job is being sent to Redis, why not do everything in Redis and ditch nanomsg?

@nickdesaulniers
Copy link
Owner

Sure, with Redis, you have a hub and spoke model. The power of nanomsg is the various network topologies that don't require a central broker.

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

No branches or pull requests

4 participants