Reputation: 1034
I'd like to know best practices for consuming messages. I've read MassTransit docs and I've searching about this but I don't get to come to any conclusion.
I have one api (hosting a bus instance) that is publishing messages. These messages are varied because this api is not a microservice (messages for purchases, sales, etc).
How do I have to organize my consumers/queues?
Upvotes: 6
Views: 1783
Reputation: 33298
The key concept is to avoid sharing a single queue for different message types. There are exceptions, but keeping each message type on a separate queue prevents bottlenecks when one message type dominates the queue traffic.
As for processes, since MassTransit can have any number of receive endpoints per bus instance, keeping related business functions in a single process can help significantly with code management and deployment. The process boundaries can be useful for scaling, for instance, adding more processes/workers for handling status updates versus new orders (the prior may be 10x the latter in terms of message volume).
Another reason to separate is dependencies, a consumer that communicates with a legacy ERP system with a lot of bindings or coupling to external libraries/SDKs might warrant a separate process just to avoid memory issues due to the way some older libraries are created. These libraries may require more frequent process restarts, etc. and keeping them separate eliminates the need to restart an entire set of consumers for the one that causes issues over time.
These are just some general guidelines, but ones that we use all the time when determining which consumers to put in the same process.
Upvotes: 4