@financialforcedev/orizuru-transport-rabbitmq
TypeScript icon, indicating that this package has built-in type declarations

5.3.0 • Public • Published

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.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 5.3.0
    0
    • latest
  • 5.0.0
    0
    • next

Version History

Package Sidebar

Install

npm i @financialforcedev/orizuru-transport-rabbitmq

Weekly Downloads

1

Version

5.3.0

License

BSD-3-Clause

Unpacked Size

72.8 kB

Total Files

18

Last publish

Collaborators

  • aditi0408
  • stephenwillcock
  • sfryffdc
  • dfruddffdc
  • mwoodffdc