Does anybody have any design patterns to cater for a situation where for a message based architecture messages do not arrive in chronological order?
Take an example of a work flow task management system, where there are two messages:
- One to create a new work flow task item;
- A second message for posting a status on the work item (e.g. 'started','finished')
In theory it is possible for the status change message to be processed BEFORE the new task message. Any suggestions on how to manage this?
There is no particular design patter for such use-case. The only thing that comes in my mind is a simple
Queue
you can use. And every programming language, I know, does have support for queues.Well ok, there might be a abstraction of design pattern you might could use here. It's called
State Pattern
where you define your states and maybe the transitions from on state to the oter. So if a state message is created you tag this message with a state you defined. And after this tagging you lookup this state in your transition table, and if it is allowed to be 'input-state' you can go on to the next state.But this just a 'kind-of-ugly-workaround' Easier would be to use a simple queue.