Scheduled Message Delivery and Execution Edit on GitHub


Note! Whenever possible, Jasper tries to use any kind of scheduled delivery functionality native to the underlying transport. If there is no native facility, this is done by polling against the configured message storage of your Jasper system.

You can send messages with Jasper, but request that the processing of the message happen at some later time with IMessageContext.ScheduleSend():


public async Task SendScheduledMessage(IMessageContext bus, Guid invoiceId)
{
    var message = new ValidateInvoiceIsNotLate
    {
        InvoiceId = invoiceId
    };

    // Schedule the message to be processed in a certain amount
    // of time
    await bus.ScheduleSend(message, 30.Days());

    // Schedule the message to be processed at a certain time
    await bus.ScheduleSend(message, DateTime.UtcNow.AddDays(30));
}

The message itself is sent out immediately, but when the receiving application sees that the message is scheduled to be processed later, the received message will be moved into the "delayed job processor" in the receiving application.

This functionality is useful for long lived workflows where there are time limits for any part of the process.

As of today, the only supported option is the default in memory option that we think is sufficient for short lived retries and limited workflow validations. In the longer term, Jasper will support database persisted delayed jobs. Follow this GitHub issue for any progress on that front.

Scheduling Jobs Locally

You also have the ability to schedule a message to be processed locally in the current system at a later time:


public async Task ScheduleLocally(IMessageContext bus, Guid invoiceId)
{
    var message = new ValidateInvoiceIsNotLate
    {
        InvoiceId = invoiceId
    };

    // Schedule the message to be processed in a certain amount
    // of time
    await bus.Schedule(message, 30.Days());

    // Schedule the message to be processed at a certain time
    await bus.Schedule(message, DateTime.UtcNow.AddDays(30));
}