@package/pubsub
easy peasy rabbitmq
Last updated a year ago by package .
MIT · Repository · Bugs · Original npm · Tarball
$ cnpm install @package/pubsub 
SYNC missed versions from official npm registry.

pubsub

wrapper around amqplib to help expediate basic stuffs.

Installation


    >$ npm install @package/pubsub

Test


    @package/pubsub>$ npm test

Build

if you want to convert @package/pubsub into es5, you can simply run:


    @package/pubsub>$ npm run build

API

create_connection(config:Object):AMQPConnection

creates a connection.

Example


    import {create_connection} from '@package/pubsub';

    // use an alternate port
    let conn = yield create_connection({ port : 5673 });

init_channel(conn:AMQPConnection, handlers:Object):AMQPChannel

create a channel, assert passed queues in handlers Object into existence and add their callbacks — if any — as consumers.

Example


    import {create_connection, init_channel} from '@package/pubsub';

    let conn = yield create_connection;

    let channel = yield init_channel(conn, {
        // assert queue into existence and consume any messages published to it
        'queue.name.1' : function* (channel, msg) {
            let data = msg.content.toString();

            console.log(msg);

            // if you want to remove this message from the queue
            channel.ack(data);
        },
        // assert queue into existence only
        'queue.name.2' : true
    });

broadcast(channel:AMQPChannel, queue:String, message:Object[, wait:Number]):Void

broadcast a message to the passed queue.

Example


    import {create_connection, init_channel, broadcast} from '@package/pubsub';

    let conn = yield create_connection;

    let channel = yield init_channel(conn, {
        'queue.name.1' : function* (channel, msg) {
            let data = JSON.parse(msg.content.toString());

            let res = yield doSomethingTo(data);

            channel.ack(msg);

            // broadcast the new message to a different queue
            yield broadcast(channel, 'queue.name.2', res);
        },
        'queue.name.2' : true
    });

destroy_queue(conn:AMQPConnection, queue1:String[, queue2:String, ..., , queueN:String]):Void

remove the passed queues, will not throw an Error if a queue does not exist.

Example


    import {conn, destroy_queue} from '@package/pubsub';

    let conn = yield create_connection;

    yield destroy_queue(conn, 'queue.name.1', 'queue.name.2');

Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 10
Dependencies (10)
Dev Dependencies (2)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |