Skip to main content

Outbox

The outbox is responsible for adding messages to the storage and then adding at least once to the transport.

builder.Services.AddTransactionalBox(x =>
{
x.AddOutbox(
storage => ...,
transport => ...,
settings => ...,
assembly => ...
);
},
settings => settings.ServiceId = "ServiceName");

Outbox Message​

info

Outbox message class name must be unique per service.

public class CreateCustomerCommandMessage : OutboxMessage
{
public Guid Id { get; init; }

public string FirstName { get; init; }

public string LastName { get; init; }

public int Age { get; init; }
}

Outbox Definition​

info

You do not need to define a outbox definition for each message.
By default, the message will be published because receiver is not indicated.

internal class CreateCustomerCommandMessageDefinition : OutboxDefinition<CreateCustomerCommandMessage>
{
public CreateCustomerCommandMessageDefinition()
{
Receiver = "Customers";
}
}

Adding a message to the outbox​


// Add in the same transaction the result of the business operation and message to outbox

await outbox.Add(message);

// Commit transaction

// After transaction is successfully commited, execute the following method
await outbox.TransactionCommited();

Storage​

Options
In Memory (Default)
Entity Framework Core (Relational)

Transport​

Options
In Memory (Default)
Apache Kafka

Settings​

AddMessagesToTransportSettings​

NameTypeDefault ValueDescription
MaxBatchSizeint5000Maximum number of processing messages per job.
LockTimeoutTimeSpan10 secondsTime to live for message blocking.

CleanUpOutboxSettings​

NameTypeDefault ValueDescription
MaxBatchSizeint10000Maximum number of messages to clean up per job.
IsEnabledbooltrueValue responsible for whether the cleaning process is enabled.

ConfigureSerialization​

NameExtension
System.Text.Json (Default)UseSystemTextJson()

ConfigureCompression​

NameExtension
No compression (Default)UseNoCompression()
BrotliUseBrotli()
GZipUseGZip()