Micro type-safe wrapper for AMQP library and RabbitMQ management
Description
Section in progress.
Getting Started
Qupi can be installed by Yarn or NPM:
npm install qupi
yarn add qupi
RabbitMQ is required for the proper functioning of the library. Feel free to use our docker-compose file. After installing Docker Desktop on your PC, docker compose up
command will create container with RabbitMQ inside.
Example
import { ConnectionFactory, Transmitter } from 'qupi';
type User = {
name: string;
age: number;
};
type Mail = {
sender: string;
recipient: string;
content: string;
};
const sendMail = (mail: Mail) => console.log(mail);
const addUser = (user: User) => console.log(user);
const start = async () => {
try {
const internalChannel = await new ConnectionFactory({
hostname: 'localhost',
password: 'root',
username: 'root',
}).createQueue('INTERNAL_QUEUE'); // createQueue method returns Qupi channel, which contains amqp channel instance and meta data.
// Transmitters receive channel as first argument, and handler as second, which is triggered by trigger function in transmitter.
const mailTransmitter = new Transmitter(internalChannel, sendMail);
const userTransmitter = new Transmitter(internalChannel, addUser);
// Transmitter class provides full autocompletion and type-safety
mailTransmitter.trigger({
sender: '[email protected]',
recipient: '[email protected]',
content: 'Hello!',
});
userTransmitter.trigger({
name: 'John',
age: 30,
});
mailTransmitter.trigger('Wrong!'); // TypeScript compiler throws an error
userTransmitter.trigger({
name: 'John',
age: '30', // Also throws an error
});
} catch (error) {
console.log(error);
}
};
start();
Contributing
Section in progress.