Sunday 18 November 2018

WebLogic Message Unit-of-Order explanation

Example for UOE(Unit Of Order)
Somebody enter in a web application (store) for buying a book and choose a book (M1= message number 1). After that, that person immediately cancel 
that action (M2= message number 2).
In this case the following things may happen:
   1) MDB 1(Message Driven Beans 1) read the first message (M1) and start processing that message.
   2) MDB2 (Message Driven Beans 2) read the second message (M2) and start processing that message.
   3) For some reasons (MDB2 run faster than MDB1), MDB2 try to cancel that operation by sending a "DELETE" operation to the database, 
but nothing happen, because MDB1 didn't "INSERT" that operation to the database.
   4) MDB1 "INSERT" that operation to the database.
At the end the book appears in the database as "INSERTED", so that book will be sent to the person who wanted it at the beginning (but is no longer needed).
In order to avoid this problem, WebLogic introduce the concept of Unit-of-Order

With this concept, more messages are associated with an ID (UOO).

The Message Unit-of-Order enforces the order of messages with the same key so that the messages are consumed in the order they were added to the queue.
Here is the behaviour we can have for the example above, if M1 and M2 have the same Message Unit-of-Order:

  • MDB 1(Message Driven Beans 1) read the first message (M1) and start processing that message.
  • MDB2 (Message Driven Beans 2) read the second message (M2) and wait for the M1 to complete.
  • MDB1 "INSERT" that operation to the database and complete the execution and MDB2 start processing that message and send a "DELETE" 
operation to the database.
All Set now.

No comments:

Post a Comment