Storing processed messages

The default behavior of a Nexus queue is to delete messages when they have been processed. But for some use cases it's interesting to keep the processed messages. You can control how for long processed messages are stored on the [Queue] attribute like this:

[Queue("example", DisplayName = "Example queue", KeepProcessedMessagesFor = "10")]
public class ExampleQueueMessage : IQueueMessage

In this example the messages are stored for 10 days. The property KeepProcessedMessagesFor should be either a string that can be parsed into a TimeSpan by TimeSpan.Parse() or the special string "forever" which tells Nexus to never delete processed messages.

Use cases

One use case for storing processed messages is to enable troubleshooting of important messages. Let's say that you have a queue of orders that should get exported to another system. The export from your side might have worked perfectly but the receiving system might reach out to you to say "hey could you send the message for order 123 again?" or "hmm what exactly did you send to us for order 123?". If you delete processed messages you'd have to dig through logs to maybe be able to reconstruct the message. If you instead keep processed messages you can easily answer both questions.

Another use case is when an external system is only able to send full exports of data rather than incremental changes. The system might be scheduled to export everything daily into a Nexus queue. If you store processed messages and turn on idempotent messages on your queue Nexus will only set messages to Pending where the data differs from yesterday.

A third use case is to do change tracking inside your queue job by reading the previous version of the message and compare the current to the previous to see what has changed. If you don't store processed messages you won't be able to load the previous message since it's been deleted.