Pattern to check if queued message can still be processed
We're building an application with multiple components that will likely send messages to each other via JMS queues. There may be times when there are significant delays (due to maintenance and the like) across these queues.
It is anticipated that some messages may become stale - i.e. the circumstances for them to exist has suddenly changed and they should be discarded at the next available opportunity.
Is there a software pattern for implementing such "staleness-checks"? Someone mentioned something about a dead snail pa开发者_开发知识库ttern but I cannot locate any references on Google...
There is not really a pattern here, because the concept is likely too situation specific.
In short, however, you will need to define staleness and check for it any time you read a message off of the queue.
As per @Space_C0wb0y's comment to the OP, this could use a simple time-to-live or other expiration timer, or it could be some other more complex check at the appropriate point in the line.
It cannot realistically, however, be implemented as a separate step in the chain that puts the message back on the queue, because in your scenario, the delay could then happen after the checks have been done.
So to reiterate, any checks of this nature would need to go at the last possible moment, in the actual processing step, after reading from the queue.
精彩评论