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
npm install amqp-extension --save
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'
});
})();
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' }
}
});
})();
Made with 💚
Published under MIT License.