Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@financialforcedev/orizuru-transport-rabbitmq

financialforcedev155BSD-3-Clause5.3.0TypeScript support: included

Rabbitmq transport layer for the orizuru package

rabbitmq, publish, subscribe, heroku, worker, dyno, orizuru

readme

Orizuru Transport RabbitMQ

Build Status

Orizuru Transport RabbitMQ is a transport library for the Orizuru framework.

It is a thin wrapper around amqplib and allows Orizuru to publish and subscribe to events via RabbitMQ.

Install

npm install @financialforcedev/orizuru-transport-rabbitmq

Usage

Use this dependency to specify the transport layer that @financialforcedev/orizuru uses as RabbitMQ.

// get classes from orizuru
import { Handler, Publisher, Server } from '@financialforcedev/orizuru';

// get the transport
import { Transport } from '@financialforcedev/orizuru-transport-rabbitmq';

// create the transport
const transport = new Transport({
    url:  process.env.CLOUDAMQP_URL || 'amqp://localhost'
});

const server = new Server({
    transport
});

const handler = new Handler({
    transport
});

const publisher = new Publisher({
    transport
});

Messages can be published to a work queue using the publisher...

import { Publisher } from '@financialforcedev/orizuru';
import { Transport } from '@financialforcedev/orizuru-transport-rabbitmq';

const transport = new Transport({
    url:  process.env.CLOUDAMQP_URL || 'amqp://localhost'
});

const app = new Publisher({ transport });

app.publish({
    message: {
        context: {},
        message: {
            test: 'message'
        }
    },
    publishOptions: {
        eventName: 'test.queue'
    }
});

and consumed by the handler.

import { Handler, IOrizuruMessage } from '@financialforcedev/orizuru';
import { Transport } from '@financialforcedev/orizuru-transport-rabbitmq';

const transport = new Transport({
    url:  process.env.CLOUDAMQP_URL || 'amqp://localhost'
});

const app = new Handler({ transport });

app.handle({
    handler: ({ context, message }: IOrizuruMessage<any, any>) => {
        app.info(context);
        app.info(message);
    }),
    schema: {
        namespace: 'testNamespace',
        name: 'testSchema',
        type: 'record',
        fields: [{
            name: 'test',
            type: 'string'
        }]
    },
    subscribeOptions: {
        eventName: 'test.queue'
    }
});

Or via a topic exchange using the publish/subscribe mechanism.

import { Handler, IOrizuruMessage, Publisher } from '@financialforcedev/orizuru';
import { Transport } from '@financialforcedev/orizuru-transport-rabbitmq';

const publisherTransport = new Transport({
    url:  process.env.CLOUDAMQP_URL || 'amqp://localhost'
});

const publisher = new Publisher({ transport: publisherTransport });

publisher.publish({
    message: {
        context: {},
        message: 'test message'
    },
    publishOptions: {
        eventName: 'test.queue',
        exchange: {
            key: 'testKey',
            name: 'testExchange',
            type: 'topic'
        }
    }
});

const handlerTransport = new Transport({
    url:  process.env.CLOUDAMQP_URL || 'amqp://localhost'
});

const app = new Handler({ transport: handlerTransport});

app.handle({
    handler: ({ context, message }: IOrizuruMessage<any, any>) => {
        app.info(context);
        app.info(message);
    }),
    schema: {
        namespace: 'testNamespace',
        name: 'testSchema',
        type: 'record',
        fields: [{
            name: 'test',
            type: 'string'
        }]
    },
    subscribeOptions: {
        eventName: 'test.queue',
        exchange: {
            key: 'testKey',
            name: 'testExchange',
            type: 'topic'
        }
    }
});

Development

Before running npm test, make sure that Docker is installed.

brew cask install docker

npm test is configured to build and start the orizuru-transport-rabbitmq--rabbitmq service, then run the system tests.

API Docs

Click to view TSDoc API documentation.

changelog

@financialforcedev/orizuru-transport-rabbitmq

5.3.0

NEW FEATURES

  • Add socketOptions to the Transport Options interface

    • This allows more flexibility when connecting to the RabbitMQ instance
  • Add a RabbitMQ Docker image that uses SSL

    • Certificates are generated within the Docker image to make configuration easier

OTHER CHANGES

  • Add system tests

    • Test on both SSL and non-SSL connections
  • Add Docker scripts to the package.json that:

    • Build the orizuru-transport-rabbitmq--rabbitmq service
    • Start the orizuru-transport-rabbitmq--rabbitmq service
    • Cleanup the created container and image
    • Start the service then run the system tests
  • Amalgamate the change log files

5.2.0

NEW FEATURES

  • Added forceSecure to the configuration options, this will force the protocol of the connection URL to be amqps

FIXES

  • Make Transport.close() flush its message channels before closing the connection

5.1.0

NEW FEATURES

  • Update typescript configuration to target es2017
  • Update all dependencies to latest versions

OTHER CHANGES

  • Remove npmignore file
  • Update to using Jest for tests

5.0.1

OTHER CHANGES

  • Update all dependencies to latest versions
  • Remove all references to new Buffer()
    • Use Buffer.from() instead to remove deprecation warnings

5.0.0

BREAKING CHANGES

  • Update Orizuru to use a class for the transport layer
    • Each server, publisher and handler should have a different transport instance
    • The configuration for the transport can be provided in the constructor thereby removing the requirement of transportConfig from Orizuru
  • Update all references to the Orizuru.Options; use Orizuru.Transport... instead
  • Remove the use of Orizuru.Transport.IConnect
  • Remove the Orizuru dev dependency

OTHER CHANGES

  • Add nyc.opts file to clean up the package.json

4.0.0

OTHER CHANGES

  • Conversion to Typescript

3.2.2

  • Dependency update for security advisories

3.2.1

  • Bug fix release

BUGS FIXED

  • Channel leak from the publisher