Sunday, January 29, 2017

Best Practice: Create correctly defined correlation ID and move it to/from MessageBroker (e.g. ActiveMQ)

Creating a correctly defined correlation ID is a must when creating integrations within the WSO2 ESB in my opinion. 
A correlation ID can consist of several ID's which have a functional meaning concatenated which uniquely determine a single message for a specific integration.
If you also give it as a property to a MessageBroker (e.g ActiveMQ) when putting a message on the queue, and similarly reading it from the MessageBroker when consuming a message, you can always follow the message flowing through the integration.
In case of an error you can see directly in the error queue what message had an issue without needing to look into a detailed and complex XML message.

Setting JMS CorrelationId in proxy before storing to Queue
<property expression="$ctx:SelfDefinedJMSCorrelationId" name="JMS_COORELATION_ID" scope="axis2" type="STRING"/>

Retrieving JMS CorrelationId in proxy after retrieving from Queue
<property expression="$axis2:JMS_COORELATION_ID" name="JMSCorrelationId" scope="default" type="STRING"/>

Furthermore it is essential that all the messages logged by a specific integration have also the correlation ID attached with it. In this way all logged messages are in context of a specific integration message, due to this functionally based correlation id.