amqp-ko
TypeScript icon, indicating that this package has built-in type declarations

1.3.0 • Public • Published

AMQP Kø CircleCI

Object oriented AMQP layer for microservices communication.

Usage

The recommended way to use AMQP Kø is to create your own queue object. The simplest way to do this is using createQueue function.

Create queue

import { createQueue, Message } from "amqp-ko";

class TopicFollow extends Message {
    constructor(userId, topicName) {
        super();
        this.userId = userId;
        this.topicName = topicName;
    }
}

class TopicFollowUnmarshaller {
    unmarshal(data) {
        return new TopicFollow(data.user_id, data.topic_name);
    }
}

const messageGates = [
    new MessageGate("topic_follow", TopicFollow, new TopicFollowUnmarshaller()),
];

const queue = createQueue("localhost", 5672, "rabbitmq", "rabbitmq", "exchange-name", messageGates);

Consume messages

class ConnectUserWithTopic {
    async consume(job) {
        // Put here some code to connect user with a topic
        // using "job.message.userId" and "job.message.topicName"
        await job.ack();
    }
}

queue.consume(
    "queue-name",
    new Map([
        [TopicFollow, new ConnectUserWithTopic()],
    ]),
);

Produce messages

const message = new TopicFollow(120, "entertainment");
queue.produce(message);

Installation

yarn add amqp-ko
npm install amqp-ko

Run tests

All of the AMQP Kø tests are written with jest. They can be run with yarn

yarn test

Package Sidebar

Install

npm i amqp-ko

Homepage

nalunch.com/

Weekly Downloads

0

Version

1.3.0

License

MIT

Unpacked Size

67.1 kB

Total Files

57

Last publish

Collaborators

  • budziam