Message Type Specific Delivery Rules Edit on GitHub


You may want to enforce some specific rules about how Jasper publishes messages on a message type by message type basis. The most common example is shown below:


// Any message of this type should be successfully
// delivered within 10 seconds or discarded
[DeliverWithin(10)]
public class StatusMessage
{
}

Custom Attributes

If you really want to, you can write your own custom attribute to modify how Jasper sends out a message by subclassing the [ModifyEnvelope] attribute. The attribute shown in the previous sample is itself implemented like that:


public class DeliverWithinAttribute : ModifyEnvelopeAttribute
{
    private readonly int _seconds;

    public DeliverWithinAttribute(int seconds)
    {
        _seconds = seconds;
    }

    public override void Modify(Envelope envelope)
    {
        envelope.DeliverBy = DateTimeOffset.UtcNow.AddSeconds(_seconds);
    }
}