[FEATURE REQ] Support for safe batching with MessageSender
See original GitHub issueIs your feature request related to a problem? Please describe. As described in https://github.com/Azure/azure-service-bus-dotnet/pull/539
The client allows to send a collection of messages (SendAsync(IList<Message>)) which is problematic when there’s a large number of messages that would not fit into the maximum message size. As a result of that, an exception is thrown when the send operation is invoked.
Describe the solution you’d like
I’d like to write the following code without worrying about an MessageSizeExceededException
await messageSender.SendAsync(bigListOfMessages);
But since there already a SendAsync
method that takes IList<Message>
one could name it SendChunkedAsync()
, SendBatchAsync()
or something else that doesn’t conflict.
I’m thinking that this method would use the current SendAsync(IList<Message>)
method to send it’s chunks of Message
s in order to pack them into as few AMPQ messages as possible.
Describe alternatives you’ve considered
-
I’ve tried to chunk the messages my self as described in this article but given that the
Size
property of theMessage
class only accounts for body size. -
This is the my current solution from my understanding sends all the messages individually. Or at least it appears so on the when looking at the code.
var sendTasks = messages
.Select(m => messageSender.SendAsync(m))
.ToArray();
await Task.WaitAll(sendTasks);
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:18 (8 by maintainers)
Top GitHub Comments
Have you considered using
Azure.Messaging.ServiceBus
, which recently went GA and is now considered the current generation library for Service Bus? It offers the ability to build a batch that is aware of size limits and that can be sent without the potential of exceeding the limit and triggering an exception.For example:
More information on
Azure.Messaging.ServiceBus
can be found on its README and samples.//cc: @JoshLove-msft
Hello all,
The newer package
Azure.Messaging.ServiceBus
is available as of November 2020. While the older packageMicrosoft.Azure.ServiceBus
will continue to receive critical bug fixes, we strongly encourage you to upgrade. Read the migration guide for more details.Closing this issue as there are no plans to add the feature discussed here to the older
Microsoft.Azure.ServiceBus
package and @jsquire has provided pointers on how to use this feature in theAzure.Messaging.ServiceBus
Thanks for your patience!