NServiceBus
NServiceBus copied to clipboard
Simplify sending large numbers of messages
This issue was transferred from a private repository
I've seen this scenario in several support cases: The user wants to send a large amount of messages via the bus to be handled. However this turns out to be non-trivial:
- When using
IMessageSession, sending large amount of messages can be very slow as don't have a proper "batching" or "session" API which allows to optimize the sends for multiple sends e.g. by reusing connections, transactions and so on. Also, error handling is important as well because with that many operations you don't want to start at 0 again in case one of 200k messages fails to send. - When using the
IMessageHandlerContext, transaction timeouts might become an issue as sending this large amount of messages can take longer than the tx timeout.
To deal with these cases, we've often seen these approaches to reduce the issue:
- Speed up sends by using parallelization. This helps to maximize available resource usage but the transport is still the biggest bottleneck. Also, parallelization can cause issues e.g. with transactions.
- Split up the "batch" into smaller batches. This requires additional logic to split, handle and track these substeps and reintroduces many concepts from batches which is what users wanted to avoid in the first place.
It would be nice to have a mechanism/API to better support sending large amount of messages.
As a first step for this, we should at least brainstorm some options to implement.