Socket
Socket
Sign inDemoInstall

rabbitmq-pub-sub

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rabbitmq-pub-sub

RabbitMq Producer and Consumer


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

rabbitmq-pubsub

TypeScript NodeJs Platform

Introduction

A typescript library for producing and consuming rabbitmq messages

If you don't have typings installed:

npm i typings -g

Getting Started

Installation

Install via npm

npm i rabbitmq-pubsub --save

Typings

You will also need these ambient dependencies:

NOTE: you might already have some of these ambient dependencies installed!

typings install amqplib bluebird bunyan node -SA

Example

import {RabbitMqConnectionFactory,RabbitMqConsumer,RabbitMqProducer,IRabbitMqConnectionConfig} from "rabbitmq-pubsub";
import {Logger} from "bunyan"

const logger: Logger = //create logger
interface IMessage{
  data: string;
  value: number;
}

// Create connection with amqp connection string
// const factory = new RabbitMqConnectionFactory(logger, "amqp://localhost:1234");

// or, create connection with host/port config
const config:IRabbitMqConnectionConfig = {
  host:"localhost",
  port:1234
}
const factory = new RabbitMqConnectionFactory(logger, config);

const consumer = new RabbitMqConsumer(logger, factory)

consumer.subscribe<IMessage>("<queue name>", m => {
  // message received
  console.log("Message", m.data, m.value)
}).then(disposer => {
  // later, if you want to dispose the subscription
  disposer().then(() => {
    // resolved when consumer subscription disposed
  });
}).catch(err => {
  // failed to create consumer subscription!
});

const producer = new RabbitMqProducer(logger, factory)

producer.publish<IMessage>("<queue name>", {data: "data", value: 23})
  .then(() => {
    // sent to queue
  }).catch((err) => {
    // failed to enqueue
  })

Consumed Libraries

amqplib

amqp library

Inspiration

Rokot - Rocketmakers

Keywords

FAQs

Package last updated on 05 Feb 2017

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