Working with the RabbitMQ queue broker.
Allows to configure exchanges
, queues
. Includes templates for Producer
, Consumer
in NodeJs.
We will add PHP support soon.
WARNING We are still updating this page Some data may be missing here — we will complete it shortly.
// rabbitmq.config.ts
import type { RabbitMQConfig } from '~/rabbitmq/types';
export const rabbitMQConfig: RabbitMQConfig = {
connection: {
url: 'amqp://localhost',
reconnectInterval: 5000,
maxRetries: 5
},
exchanges: [
{
name: 'demo1.events.v1',
type: 'direct',
options: { durable: true }
}
],
queues: [
{
name: 'demo1.v1',
options: { durable: true },
bindings: [
{
exchange: 'demo1.events.v1',
routingKey: 'event.succeeded'
}
]
}
],
channel: {
prefetchCount: 1
}
};
// producers/demo1-producer.ts
import { RabbitMQProducer } from '~/rabbitmq/producer';
import { rabbitMQConfig } from '../rabbitmq.config';
const producer = new RabbitMQProducer(rabbitMQConfig);
export async function sendTask(dots: string) {
await producer.publish(
'demo1.events.v1',
'event.succeeded',
{ task: dots },
{ persistent: true }
);
console.log(`Sent task: ${dots}`);
}
// Example message sending
const tasks = ['...', '....', '.....', '..', '.'];
tasks.forEach(async (task) => {
await sendTask(task);
await new Promise(resolve => setTimeout(resolve, 1000));
});
More examples can be found in documentation and in @bitrix24/app-template-automation-rules