Customizing the Sent Message Envelopes Edit on GitHub


The IServiceBus.Send(message, Action<Envelope>) method allows you to override how a Jasper message is sent and even processed by directly altering the Envelope:


public Task CustomizingEnvelope(IMessageContext bus)
{
    return bus.Send(new SomeMessage(), e =>
    {
        // Override the message routing
        e.Destination = new Uri("tcp://server1:2000");

        // Force Jasper to send the message serialized
        // with a certain content-type
        e.ContentType = "application/xml";


        // Make this a scheduled job
        e.ExecutionTime = DateTime.UtcNow.AddDays(1);


        // Direct the receiver that the sender is interested in any response
        // with this message type
        e.ReplyRequested = "other-message-type";

        // Probably easier to use this extension method though
        e.ReplyRequested = typeof(Message2).ToMessageAlias();

        // This envelope should be discarded if not processed
        // successfully within 5 days
        e.DeliverBy = DateTimeOffset.UtcNow.AddDays(5);


        // Discard the message after 20 seconds if
        // not successfully processed before then
        e.DeliverWithin(20.Seconds());
    });