Coder Social home page Coder Social logo

amqpclient's Introduction

AMQP Client

Build Status

An AMQP Client of Node.js base on amqplib with auto reconnect

Quick Start

Consumer

const AMQPClient = require('amqp.node.client');
const consumer = new AMQPClient({}, 1000);

const q = 'amqpclient.test';

consumer.start((ch) => {
  return ch.assertQueue(q).then(ok => {
    return ch.consume(q, (msg) => {
      msg.should.be.Object();
      if (msg) {
        let body = msg.content.toString();
        console.log(body);
        ch.ack(msg);
      }
    });
  });
});

Disconnect

$ rabbitmqctl close_all_connections test_reconnect_case

Producer

const AMQPClient = require('amqp.node.client');
const consumer = new AMQPClient();

const q = 'amqpclient.test';
const message = 'test message';

producer.start(ch => {
  ch.assertQueue(q).then(ok => {
    ch.sendToQueue(q, Buffer.from(message));
  });
});

RPC

Server

/**
 * @name rpcServer
 * @param  {function} srv must return Promise Object;
 * @param  {object} rpcOptions optional
 */
rpcServer.rpcService(opts=>{
  const res = parseInt(opts.a)+parseInt(opts.b);
  return Promise.resolve({val: res});
}, {queue: 'my.custom.rpc.request.queue.name'}).then(res=>{
  console.log('rpc server ready');
});

Client

rpcClient.rpc({a:1, b:2}, {queue: q}).then(res=>{
  res.val.should.be.equal(3);
});

Environment

  • RABBITMQ_HOST default host if set
  • RABBITMQ_VHOST default vhost if set
  • RABBITMQ_USER default username if set
  • RABBITMQ_PWD default password if set
  • RABBITMQ_PORT default port if set

amqpclient's People

Contributors

guanbo avatar

Stargazers

Marius avatar

Watchers

 avatar James Cloos avatar  avatar

Forkers

terrynie

amqpclient's Issues

rabbitmq unreachable protected

rabbitmq unreachable

[AMQP] reconnect:localhost
[AMQP] createChannel for worker
(node:1) UnhandledPromiseRejectionWarning: TypeError: conn.createChannel is not a function
    at connect.then.conn (/home/node/ncwz-node/node_modules/amqp.node.client/index.js:64:19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.