Novelty Plastic Moustache
Unleash awesomeness. Private packages, team management tools, and powerful integrations. Get started with npm Orgs »

@financialforcedev/orizuru-transport-rabbitmq

5.0.1 • 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'
        }
    }
});

API Docs

Click to view TSDoc API documentation.

install

npm i @financialforcedev/orizuru-transport-rabbitmq

Downloadsweekly downloads

67

version

5.0.1

license

BSD-3-Clause

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
Report a vulnerability