Oversized Sends

This page refers to the legacy Azure Service Bus transport that uses the WindowsAzure.ServiceBus NuGet package. This package is currently on extended support until May 2022, after which it will be out of support according to the support policy. All users should migrate to the Azure Service Bus transport transport.

The Azure Service Bus SDK attempts to prevent sending messages that exceed the maximum message size. 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 reported only 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 :
    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