Messages
Messages implement IMessage and support multiple handlers. When published, the worker discovers all registered handlers and creates a separate job for each — pub/sub style.
Define a message
public class OrderPlaced : IMessage
{
public int OrderId { get; set; }
}
Define handlers
public class SendConfirmationEmail : IMessageHandler<OrderPlaced>
{
public async Task HandleAsync(OrderPlaced message, CancellationToken ct)
{
// Send email
}
}
public class NotifyWarehouse : IMessageHandler<OrderPlaced>
{
public async Task HandleAsync(OrderPlaced message, CancellationToken ct)
{
// Notify warehouse
}
}
Publish
await publisher.Publish(new OrderPlaced { OrderId = 123 });
await context.SaveChangesAsync(); // Persisted atomically with your data
How it works
Publish()creates aJobentity withKind = Messagein the databaseMessageRouterdiscovers all registeredIMessageHandler<T>implementations- For each handler, a child
Jobis created withKind = Joband the handler pre-assigned - Workers pick up each child job and execute it independently
- When all children complete, the parent message transitions to
CompletedorFailed
Messages are visible in the dashboard under the Messages tab.