1.3.0 • Published 4 years ago

amqp-ko v1.3.0

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

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

Author: Michał Budziak

1.3.0

4 years ago

1.2.0

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago