Skip to content

[Feature] Azure Service Bus to use ServiceBusMessageBatch with fallback to SendMessage #3694

Description

@mikechrisfreeman

Problem
Currently the IServiceBusSenderWrapper implements SendAsync(ServiceBusMessage message..) and SendAsync(ServiceBusMessage[] messages, ..)

Whilst premium tiers of Azure Service Bus support message sizes of 100MB a batch can only be a max size of 1MB.

We're using Microsofts SendMessage**s**() implementation, it does not make use of ServiceBusMessageBatch which gives us a view on when we're exceeding the threshold.

Exceeding the size limits produces various exceptions

Running a batch >1MB through SendMessage**s**():

System.InvalidOperationException : The link 'G1:39496958:amqps://rev-recog-test.servicebus.windows.net/-e446fcba;0:5:6' is force detached by the broker because publisher(link34(39496966_G1)) received a batch message with no data in it. Detach origin: Publisher.
For troubleshooting information, see https://aka.ms/azsdk/net/servicebus/exceptions/troubleshoot.

(Try to) Create a message batch with a max batch size >1MB
System.ArgumentOutOfRangeException : Value is greater than the maximum allowed. (Parameter 'MaxSizeInBytes')

Solution
Proposal to use ServiceBusMessageBatch.TryAddMessage which will allow us to batch on size, not on number. A fallback solution if a single message exceeds the allowed batch size (1MB) to use SendAsync(ServiceBusMessage message, ..)

This will allow use to batch on size and but also produce messages up to Azure Service Bus allowed quotas.

(an inflight pr will allow us to make these changes with little impact as generic batches need to implement an IAmAMessageBatch interface)

Additional context
Ref : https://docs.azure.cn/en-us/service-bus-messaging/service-bus-quotas

Image

Activity

  1. added theissue type on Aug 5, 2025
  2. changed the issue type fromtoon Aug 5, 2025
  3. mikechrisfreeman commented on Aug 5, 2025

    @mikechrisfreeman
    ContributorAuthor

    Thanks for the tags @lillo42 - you can assign this guy to me as i'll be picking it up next. Also can you tag it with V10 please?

  4. mikechrisfreeman commented on Aug 8, 2025

    @mikechrisfreeman
    ContributorAuthor

    @iancooper - I don't think this change would be considered breaking, more fixing 🩹 . So I think it would just be an incremental update to v10?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions