AlariCode / nestjs-rmq

A custom library for NestJS microservice. It allows you to use RabbitMQ or AMQP.
https://purpleschool.ru
MIT License
285 stars 38 forks source link

Add queues per function #27

Closed bmcgoncalves closed 3 years ago

bmcgoncalves commented 3 years ago

Add this feature if its possible. We would like to add queues per function. Users using rabbitmq only need to know the name of the functions.

@RMQRoute({queue: '/cmd/sum', 'routingKey': '/cmd/sum', ...})
sum(numbers: number[]): number {
    return numbers.reduce((a, b) => a + b, 0);
}

@RMQRoute({queue: '/cmd/info', 'routingKey': '/cmd/info', ...})
info(data: string) {
    console.log(data);
}

`

Example: image

image

AlariCode commented 3 years ago

@bmcgoncalves, thanks for suggestion! Can you describe use case when you need to listen to more than one queue? Why can't you subscribe to one queue and use Topic to route messages to functions? You can name queue like "myService.queue" and add routes:

This adds more complexity to routing and managing queues. You need to keep in mind that your service consumes more than one queue.

bmcgoncalves commented 3 years ago

Hi,

Imagine if I have 1000 microservices connected to the same queue. I'm new to rabbitmq but I think this is not a good practice.

I want to create microservices in NestJs and make them"auto registered" in the rabbitmq to make my functions available to all others microservices. The developer making a a microservice only need to know the Routing-Key/queue (the same string) and call services by function name (Routing-Key).

AlariCode commented 3 years ago

Good practice in RMQ - you have 1 queue per service. So when you have 1000 different services you will have 1000 queues. But if you have same services (for load balancing) they will be connected to the same queue and process messages one by one. But if you have 1 service connected to multiple queues - this may cause queue management problem.