Scheduling a Message
How-to · Applies to Brighter V10 · Prerequisites: Scheduler
This page shows you how to schedule a message or request for deferred execution, how to cancel one you have already scheduled, and how to configure each scheduler for the job. For what scheduling is and which scheduler to pick, see Scheduler.
Message Scheduling Code Examples
Basic Scheduling with DateTimeOffset
Schedule a command for a specific absolute time:
// ...
public class OrderService
{
private readonly IAmACommandProcessor _commandProcessor;
public async Task CreateOrder(Order order)
{
// Save order
await _repository.SaveAsync(order);
// Schedule order processing for tomorrow at 9 AM
var processTime = DateTime.UtcNow.Date.AddDays(1).AddHours(9);
var schedulerId = await _commandProcessor.SendAsync(
new DateTimeOffset(processTime),
new ProcessOrderCommand { OrderId = order.Id }
);
// Store scheduler ID for potential cancellation
order.ProcessSchedulerId = schedulerId;
}
}Basic Scheduling with TimeSpan
Schedule a command with a relative delay:
Scheduling with Post for External Bus
Schedule a message to an external broker:
Cancelling a Scheduled Message
Cancel a previously scheduled message:
Note: Every scheduler supports cancellation. Rescheduling is the operation that varies: the Azure Service Bus scheduler does not reschedule, so cancel the message and schedule it again instead. See Choosing a Scheduler.
Retry with Exponential Backoff
Implement retry logic with increasing delays:
Using Requeue with Delay in a Handler
Message Scheduling Configuration Examples
Configuring with Hangfire
Configuring with Quartz.NET
Configuring with InMemory (Development Only)
Further Reading
Scheduler - What scheduling is, and choosing a scheduler
Switching Schedulers - Moving from one scheduler to another
Custom Scheduler - Implementing your own scheduler
Handler Failure - Error handling and retry strategies
Last updated
Was this helpful?
