Patterns for messages not arriving in chronological order

73 views Asked by At

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?

2

There are 2 answers

2
ckruczek On

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.

0
Zelldon On

If I'm understanding the question right:

You want to process state messages before the task is created, which could be made in theory.

So you must consider two possible cases:

1. The state message is recieved before the task creation message:

Create the corresponding task and set the state of the Task to the value of the state message. Maybe after that, the task creation message is recieved. Check if the task was created if so do nothing otherwise create the task.

2. The task creation message was recieved before the state message:

This is the normal case you create simply the task and if you recieve the state message set the state of the task to the value of the state message.