Oversized Sends

Component: Azure Service Bus Transport
NuGet Package NServiceBus.Azure.Transports.WindowsAzureServiceBus (8-pre)
Target NServiceBus Version: 6.x
This page targets a pre-release version and is subject to change prior to the final release.

As mentioned in error handling the Azure Service Bus SDK has a peculiar behavior when it comes to computing the message size, resulting in the possibility that oversized messages get sent even when not intended.

The transport handles this scenario by advising to use the databus to send oversized messages instead. However, in certain scenarios, this is not the desired behavior. Therefore it is possible to override this behavior.

One such scenario is, for example, an HTTP API that allows bulk uploading of arrays of entities to process. The API has logic to split these arrays into parts that would normally fit inside a brokered message, but due to the unknown entity property content and the internal serialization overhead associated with that, the message suddenly exceeds the maximum body size. In this scenario, the message to be sent would be lost, and it would be up to the caller of the API to deal with the problem.

Configuring an oversized brokered message handler

To provide an alternate behavior, a custom implementation of IHandleOversizedBrokeredMessages can be configured

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