Can outbox feature be ignored for few handlers

hi all,

Scenario:
we have configured our azure function endpoint with the outbox feature, using cosmos persistence for a saga.

we have based our implementation using the sample:
Cosmos DB Persistence Usage with transactions • NServiceBus.Persistence.CosmosDB Samples • Particular Docs

as mentioned in the sample, we have all the messages with the IProvideOrderId interface, like below

var transactionInformation = persistence.TransactionInformation();
transactionInformation.ExtractPartitionKeyFromMessage<IProvideOrderId>(provideOrderId =>
{
    Log.Info($"Found partition key '{provideOrderId.OrderId}' from '{nameof(IProvideOrderId)}'");
    return new PartitionKey(provideOrderId.OrderId.ToString());
});

Issue:

  1. On this endpoint we implemented a new EmailHandler, which receives a message from a httpfunction trigger that does not implement the IProvideOrderId interface, and we are running into the following exception.

For the outbox to work a partition key must be provided at latest up to the incoming physical or logical message stage. Set one via ‘{nameof(CosmosPersistenceConfig.TransactionInformation)}’.

how can we exclude this particular message to be excluded ?,

httptrigger code for sending the message

   var sendOptions = new SendOptions();
   sendOptions.RouteToThisEndpoint();

   await functionEndpoint.Send(new EmailMessage(Email=emailbody), sendOptions, executionContext);

Thanks -Nen.

Hi Nen!

The partition key extractors are additive so you can add one for your email message that use a different property or the NServiceBus message id.

transactionInformation.ExtractPartitionKeyFromMessage<IProvideOrderId>(...);
transactionInformation.ExtractPartitionKeyFromMessage<EmailMessage>((message, headers) =>
        {
            // use some property of the email message
            return new PartitionKey(message.EmailAddress.ToString());

            // or use the message id header
            //return new PartitionKey(headers[NServiceBus.Headers.MessageId]);
        });

how can we exclude this particular message to be excluded

It’s not currently possible to skip the outbox

Side note: From a design perspective you might want to consider splitting those email messages out to a separate endpoint since that would give you better control over scaling, recoverability settings, throttling, transactionality etc