Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@coolgk/amqp

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@coolgk/amqp

a simple RabbitMQ (amqp wrapper) class for publishing and consuming messages

  • 2.0.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-90%
Maintainers
1
Weekly downloads
 
Created
Source

@coolgk/amqp

a javascript / typescript module

npm install @coolgk/amqp

a simple RabbitMQ (amqp wrapper) class for publishing and consuming messages

Report bugs here: https://github.com/coolgk/node-utils/issues

Examples

import { Amqp } from '@coolgk/amqp';
// OR
// const { Amqp } = require('@coolgk/amqp');

const amqp = new Amqp({
    url: 'amqp://localhost/vhost'
});

const message = {
    a: 1,
    b: 'b'
};

// CONSUMER MUST BE STARTED FIRST BEFORE PUSHLISHING ANY MESSAGE

// consumer.js
// consume message and return (send) a response back to publisher
amqp.consume(({rawMessage, message}) => {
    console.log('consumer received', message); // consumer received ignore response
                                               // consumer received { a: 1, b: 'b' }
    return {
        response: 'response message'
    }
});

// publisher.js
// publish a message, no response from consumer
amqp.publish('ignore response');

// publish a message and handle response from consumer
amqp.publish(message, ({rawResponseMessage, responseMessage}) => {
    console.log('response from consumer', responseMessage); // response from consumer { response: 'response message' }
});


// example to add:
// consume from (multiple) routes
// round robin consumers
// direct route + a catch all consumer

Amqp

Kind: global class

new Amqp(options)

ParamTypeDescription
optionsobject
options.urlstringconnection string e.g. amqp://localhost
[options.sslPem]stringpem file path
[options.sslCa]stringsslCa file path
[options.sslPass]stringpassword

amqp.closeConnection() ⇒ void

Kind: instance method of Amqp

amqp.publish(message, [callback], [options]) ⇒ promise.<Array.<boolean>>

Kind: instance method of Amqp

ParamTypeDefaultDescription
message*message any type that can be JSON.stringify'ed
[callback]functioncallback(message) for processing response from consumers
[options]object
[options.routes]string | Array.<string>"['#']"route names
[options.exchangeName]string"'defaultExchange'"exchange name

amqp.consume(callback, [options]) ⇒ promise

Kind: instance method of Amqp

ParamTypeDefaultDescription
callbackfunctionconsumer(message) function should returns a promise
[options]object
[options.routes]string | Array.<string>"['#']"exchange routes
[options.queueName]string"''"queue name for processing messages. consumers with the same queue name process messages in round robin style
[options.exchangeName]string"'defaultExchange'"exchange name
[options.exchangeType]string"'topic'"exchange type
[options.priority]number0priority, larger numbers indicate higher priority
[options.prefetch]number11 or 0, if to process request one at a time

amqp.getChannel() ⇒ promise

Kind: instance method of Amqp
Returns: promise - - promise

Keywords

FAQs

Package last updated on 21 Feb 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc