Skip to content

This is a library on top of the amqplib library and is meant to simplify the process of consuming & publishing queue messages.

License

Notifications You must be signed in to change notification settings

tada5hi/amqp-extension

Repository files navigation

AMQP Extension 🏰

npm version codecov Master Workflow Known Vulnerabilities semantic-release: angular

This is a library on top of the amqplib library and is meant to simplify the process of consuming & publishing queue messages.

Table of Contents

Installation

npm install amqp-extension --save

Usage

Publish

The publish method allows you to send messages quickly.

import { Client } from "amqp-extension";

const client = new Client({
    connectionOptions: 'amqp://<user>:<password>@<host>',
    exchange: {
        name: '<name>',
        type: 'topic'
    }
});

(async () => {
    await client.publish('<routing-key>', {
        foo: 'bar'
    });
})();

Consume

To consume a queue use the consume function.

import {
    Client,
    ConsumeMessage,
    ConsumeOptions,
} from "amqp-extension";

const client = new Client({
    connectionOptions: 'amqp://<user>:<password>@<host>',
    exchange: {
        name: '<name>',
        type: 'topic'
    }
});

(async () => {
    await client.consume('<routing-key>', {
        $any: async (message: ConsumeMessage) => {
            const content = message.content.toString('utf-8');
            const payload = JSON.parse(content);
            console.log(payload);
            // { type: 'resourceCreated', name: 'foo' }
        }
    });
})();

License

Made with 💚

Published under MIT License.

About

This is a library on top of the amqplib library and is meant to simplify the process of consuming & publishing queue messages.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published