Thursday, December 19, 2019

12c SOA - Oracle Mediator part2 - Resequencer

"The Resequencer in Mediator rearranges a stream of related but out-of-sequence messages into a sequential order. When incoming messages arrive, they may be in a random order. The resequencer orders the messages based on sequential or chronological information, and then sends the messages to the target services in an orderly manner. The sequencing is performed based on the sequencing strategy selected."

Mediator can resequence the incoming messages in a user-specified order. This implementation enables you to specify three types of resequencing orders:
  • Standard Resequencer
  • FIFO Resequencer
  • Best Effort Resequencer
Mediator Processing without Resequencing:
Standard – Processes transactions contiguously within a Group, based on a defined Group and Sequence ID.  Groups are processed in parallel.
FIFO (First-In-First-Out) – Processes transactions based on the time they are received by the Resequencer.
Best Effort – Processes transactions based on Sequence ID in increasing order at predefined intervals. Best Effort transaction processing is not always contiguous.

Implementation using Standard type:
  • When using the standard resequencer in Mediator, you must always specify a group XPath expression and a sequence ID XPath expression. These specify where theMediator resequencer can find the group and the sequence ID in the messages. 
  • You must also supply the sequence numbering in terms of the start sequence ID and the sequence ID incremental delta. This numbering is used to form each group. 
  • In addition to the group, sequence ID, and increment properties, you can also specify a timeout period, in seconds, to wait for the expected messages.
The Mediator standard resequencer holds back messages in the Mediator resequencer database until it can produce the right sequence for different groups. This situation means that if for a given group, the message with a particular sequence ID does not arrive within the timeout period, the subsequent messages for that group are held back forever. In such a case, you must manually unlock the group through Oracle Enterprise Manager Fusion Middleware Control and go to the next available message,
skipping the pending message.

Schema used:
<?xml version="1.0" encoding="windows-1252" ?>
<xsd:schema xmlns:xsd="" xmlns="http://www.emp.poc" targetNamespace="http://www.emp.poc"
  <xsd:element name="process">
        <xsd:element name="empID" type="xsd:string"/>
        <xsd:element name="empType" type="xsd:string"/>
        <xsd:element name="empName" type="xsd:string"/>

Create a SOA project and above schema file and drag and drop mediator
 Use One way Interface and use the schema.

 Choose Re-sequence level as Component.
 Choose Resequence mode as Standard.
 Select the Xpaths for Group and ID. Here we use empType as Group and empID and ID.
For the Resequence Level we can select ‘operations’ or ‘component’.
For Mediator components which only have 1 operation it doesn’t matter which one we select. For a Mediator component which consists of more then 1 operation and selecting the ‘component’ option means resequencing is applied to all operations in it. For this test we selected the ‘component’ option and used the ‘Standard’ mode.
About options to configure the re-sequencer.
Group – xpath expression to the field in the payload which the resequencer will use to group our incoming messages
ID – xpath expression to the field which will uniquely identify our message
Start – Start value of the ID in the incoming message
Increment – Value which will be used for the increment of the id field in the upcoming messages
Timeout – Time to wait before a following expected message arrives at the Mediator component

 Create a file adapter to write the files in a local directory.

 Now wire it
 Do the transformation

 Deploy to the server and test

test with ID= 1 and Group = TMP
 test with ID= 3 and Group = TMP
 Observed that the transaction (id=3) went to running state and waiting for the ID=2 which is not processed yet.
 Test with ID=2 and group=TMP
 Now 1st process ID=2 and then ID=3.

Implementation using FIFO Resequencer:
  • The FIFO resequencer supports a standard first in, first out (FIFO) pattern.The FIFO resequencer receives a stream of messages that are in order and processes them in sequence for each group based on the arrival time of the messages.
  • When using the FIFO resequencer, you must always specify a group XPath expression. However, you do not need to specify a sequence ID because the messages are processed according to the time of arrival to the Mediator service component that isconfigured for FIFO resequencing. The group XPath expression specifies where the FIFO resequencer should find the group information in the message to group the messages. No further configuration is needed for a FIFO pattern.

Test with ID=1 and group=PERM
 Test with ID=3 and group=PERM
 Test with ID=2 and group=PERM
 Its processed 1,3 and 2 in FIFO manner.

Implementation using Best Effort Resequencer:
  • The best effort pattern is useful for applications that produce a large number of messages in a short period and cannot provide information to the resequencer about the identifier to use for sequencing. Typically, the identifier used for sequencing in Resequencing Order such scenarios is of a dateTime type or numeric type. Using the dateTime field as the sequence ID XPath enables you to control the sequencing. The messages are expected to be sent in sequence by the applications, thus the date and time the messages are sent can be used for sequencing. The Mediator makes the best effort to ensure that the messages are delivered in sequence.
  • The best effort resequencer can reorder messages based on no knowledge about the increment of the sequence ID. This situation means that unlike the standard resequencer, you do not need to define the increment of the sequence ID for the best effort resequencer in advance. When the messages are processed, they are processed in sequence based on the specified sequence ID and the messages that have arrived, whether a true sequence is received. The sequence IDs are either numeric or dateTime. Therefore, sequencing occurs on the numeric order or the dateTime order of the sequence IDs.
When using the best effort resequencer, you must specify a group XPath expression, a sequence ID XPath expression, and the data type of the sequence ID (numeric or dateTime). These specify where the resequencer should find the group and the sequence ID in the messages and how to handle the sequence ID. In addition, you must specify either a maximum number of rows to select for each resequencing batch or a time window during which the messages included in one batch arrive. Unlike the standard resequencer, the best effort resequencer has no knowledge about how the sequence is built. No further information

Example of Best Effort Resequencing Based on Maximum Rows
In this example, msgX(Y,Z) indicates that the message arrives as message number X to the Mediator service component and the message contains sequenceID Y and group Z.
Group C 

Sequenced Messages

Example of Best Effort Resequencing Based on a Time Window
In this example, the time window is 10 minutes, the buffer is 10% (one minute), and msgX(Y) indicates that the message arrives as message number X to the Mediator service component and the message contains the sequence ID Y. The first message arrives at 2:00:00, which starts the time window. The time window lasts until 2:10:00, but with the addition of the buffer time, messages that arrived until 2:11:00 are processed.
Group C

Sequenced Messages
msg03(01), msg06(02), msg04(03), msg01(04), msg02(05),
msg09(06), msg05(07), msg08(08), msg12(09), msg11(10),
msg10(12), msg07(13)

In the above example, the resequencer identified the maximum sequence ID for the time window as 13 (from message 7). Message 13 arrived within the buffer time, but has a sequence ID of 14. It is not processed with the original group, but instead begins a new time window at its arrival time of 2:10:50. Message 14 arrived too late and is included in the second time window.

No comments:

Post a Comment

Featured Post

11g to 12c OSB projects migration points

1. Export 11g OSB code and import in 12c Jdeveloper. Steps to import OSB project in Jdeveloper:   File⇾Import⇾Service Bus Resources⇾ Se...