Oversized Sends

Component: Azure Service Bus Transport (Legacy)
NuGet Package NServiceBus.Azure.Transports.WindowsAzureServiceBus (7.x)
Target NServiceBus Version: 6.x
Standard support for version 6.x of NServiceBus has expired. For more information see our Support Policy.
This page refers to the deprecated legacy Azure Service Bus transport that uses the WindowsAzure.ServiceBus NuGet package. All users should migrate to the Azure Service Bus transport 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 data bus feature, however using the data bus feature is not always desirable, especially when exceeding the message size limits of Azure Service Bus is uncommon.

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

Configuring an oversized brokered message handler

class CustomOversizedBrokeredMessageHandler :
    IHandleOversizedBrokeredMessages
{
    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();
messageSenders.OversizedBrokeredMessageHandler(oversizedMessageHandler);

Last modified