Oversized Sends

This page refers to the legacy Azure Service Bus transport, which is rendered obsolete by the Azure Service Bus transport built to target both .NET Framework and .NET Core. All new projects should use the new Azure Service Bus transport.

The Azure Service Bus SDK attempts to prevent sending of messages that exceed the maximum message size supported by the SQS broker by calculating the size using the body of the message, however it does not take into account headers or overhead added by serialization performed in the SDK. As a result oversized messages may be sent to the broker and only reported after the message has been rejected and discarded by the Azure Service Bus broker.

The transport deals with this problem for a large part by performing an estimated size calculation that includes both body and headers as well as a percentage for padding as an attempt to compensate for additional message serialization performed by the SDK.

The recommended way to send message payloads which may exceed the transport message size limits is to use the NServiceBus DataBus feature, however using the DataBus feature is not always desirable, especially when exceeding the message size limits of Azure Service Bus is uncommon.

As an alternative to using the DataBus feature, a custom implementation of IHandleOversizedBrokeredMessages can be configured

Configuring an oversized brokered message handler

class CustomOversizedBrokeredMessageHandler :
    public Task Handle(BrokeredMessage brokeredMessage)
        // do something useful with the brokered message
        // e.g. store it in blob storage
        return Task.CompletedTask;

and registered using the OversizedBrokeredMessageHandler API.

var transport = endpointConfiguration.UseTransport<AzureServiceBusTransport>();
var messageSenders = transport.MessageSenders();
var oversizedMessageHandler = new CustomOversizedBrokeredMessageHandler();

Last modified