async-client

1.0.0 • Public • Published

Publish / Subscribe Client (Support to generators)

Now only support to Redis. In the future we'll add support to amqp protocol.

Install

npm install --save https://github.com/Vizzuality/async-client-nodejs.git

Use

You have examples in examples folder. To execute example: node example/redis.js

Code:

'use strict';
const CHANNEL = 'myChannel';

function* iter(number) {
    for (var i = 0; i < number; i++) {
        yield i;
    }
}

function* gen(number) {
    for (var val of iter(number)) {
        console.log(val);
    }
}

var AsyncClient = require('../index');

var asyncClientPublish = new AsyncClient(AsyncClient.REDIS, {
    host: 'localhost' // redis url
});
var asyncClientSubscriber = new AsyncClient(AsyncClient.REDIS, {
    host: 'localhost'// redis url
});

var channelSubscribe = asyncClientSubscriber.toChannel(CHANNEL);
channelSubscribe.on('message', function*(channel, message) {
    console.log('Message received: ' + message);
    yield gen(message);
    console.log('Message completed');
});
channelSubscribe.subscribe();

asyncClientPublish.toChannel(CHANNEL).emit(2);
asyncClientPublish.toChannel(CHANNEL).emit(5);

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.0
    1
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.0
    1

Package Sidebar

Install

npm i async-client

Weekly Downloads

1

Version

1.0.0

License

MIT

Last publish

Collaborators

  • andres.gonzalez
  • davidsingal
  • mbarrenechea
  • clementprdhomme
  • tiagojsag
  • d4weed
  • hotzevzl