IronMQ now supports three new operations: peek, touch and release. These operations give you greater control over handling your messages and here’s a brief explanation of each.
A little background on the message lifecycle
First off, let’s discuss the typical message lifecycle.
- POST message to a queue.
- GET message from the queue – this reserves it.
- DELETE message from the queue once you’re done with it.
During the 2nd phase of the lifecycle, the GET phase, a message is reserved for a period of time defined by the “timeout” parameter (default is 60 seconds). If the message is not DELETEd before the end of the timeout, it will be placed back on the queue and become available again for the next GET.
Peek allows you to get messages off the queue without reserving them. Peek will not reserve the message and it will therefore remain available for the next peek or get operation. You can use this if you need to see if any messages are available.
Touching a reserved message extends its timeout by the duration specified when the message was created / POSTed. This is useful if your processing time is taking longer than expected and you want some more time to finish.
Releasing a reserved message un-reserves the message and puts it back on the queue as if the message had timed out. This is useful if for some reason you can’t process the message right away, you can put it back on the queue for another process to pick up. You can also supply a “delay” parameter.