Skip to main content

Inbox

The inbox is responsible for getting messages from the transport and adding them to the storage, and then processes these messages.

tip

You can run inbox as a standalone service. You add reference to shared assemblies, but deploy as separate services. This way, processing in inbox does not affect the performance of your service.

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

Inbox Message

info

Inbox message class name must be unique per service.

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

public string FirstName { get; init; }

public string LastName { get; init; }

public int Age { get; init; }
}

Inbox Definition

info

You do not need to define a inbox definition for each message.
Listens by default for incoming messages to the current service (does not listen on events).
If you want to listen for events, you need to define the PublishedBy property.

public class CreatedCustomerEventMessageDefinition : InboxDefinition<CreatedCustomerEventMessage>
{
public CreatedCustomerEventMessageDefinition()
{
PublishedBy = "Customers";
}
}

Handling message in inbox handler

info

Each InboxMessage must have a IInboxHandler declared.

public class CreatedCustomerEventMessageHandler : IInboxHandler<CreatedCustomerEventMessage>
{
...

public async Task Handle(CreatedCustomerEventMessage message, IExecutionContext executionContext)
{
// Your logic
}
}

Storage

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

Transport

Options
In Memory (Default)
Apache Kafka

Settings

AddMessagesToInboxSettings

NameTypeDefault ValueDescription
DefaultTimeToLiveIdempotencyKeyTimeSpan7 daysDefault time to live idempotency key. After the time expires, the key will be removed.

CleanUpInboxSettings

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

CleanUpIdempotencyKeysSettings

NameTypeDefault ValueDescription
MaxBatchSizeint10000Maximum number of idepotency keys to clean up per job.
PeriodTimeSpan1 hourTime interval between cleaning idepotency keys.

ConfigureDeserialization

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