What happens to a message going through WSO2 ESB synapse mediation engine ( Looking up the source code)
In the previous blog post [1], I have discussed about the PassThrough Transport and how it works. If you follow this [2] article, you can learn about what is happening inside PTT when a message is received. The below diagram depicts the relationship of PTT, Axis2 and Synaps Mediation engine within WSO2 ESB.
As depicted in the above diagram, When a message comes to the ESB, it will be received by the reactor thread of Pass Through Listener and the message will be read in to an internal buffer. Then it will be processed through a separate worker thread and will flows through the Axis2 In message flow. Then Axis2 engine will call the respective message receiver (SynapseMessageReceiver, ProxyMessageReceiver or SynapseCallbackReceiver) class. This would be the main entry point to the synapse mediation engine. Then it will go through the synapse mediation flow and handed over to Axis2FlexibleMEPClient and and it will hand over the message to Axis2 engine for the out flow. Then the message will be send to the backend through PassThroughSender thread.
This is a high level description of what happens inside WSO2 ESB. The following section will describe what happens within the synapse mediation engine when it receives by the MessageReceiver interface class.
I am taking the following sample ESB configuration for this debugging session. It contains all the basic elements of a proxy service definition which are
InSequence
OutSequence
FaultSequence
Endpoint
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="DebugProxy"
transports="https,http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<log level="full">
<property name="IN_SEQ" value="Executing In Sequence"/>
</log>
</inSequence>
<outSequence>
<log level="full">
<property name="OUT_SEQ" value="Inside the out sequence"/>
</log>
<send/>
</outSequence>
<faultSequence>
<log level="full">
<property name="FAULT_SEQ" value="Inside Fault Sequence"/>
</log>
</faultSequence>
<endpoint>
<address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
</endpoint>
</target>
<description/>
</proxy>
Here I have used the log mediator with level “full” such that message will be converted in to canonical format (building the message) within the ESB.
The below description provides information on the classes and methods executed when a message received from a client to the ESB. This will be really helpful when you are debugging a particular issue related to ESB and you can start debugging at a desired level without starting from the beginning.
Request Path
AxisEngine.receive()
ProxyServiceMessageReceiver.receive()
————————————
Get the Fault Sequence and push in to fault handler stack
————————————
Execute the inSequence
SequenceMediator.mediate()
AbstractListMediator.mediate()
RelayUtils.buildMessage()
DeferredMessageBuilder.getDocument()
SOAPBuilder.processDocument()
LogMediator.mediate()
————————————
If the inSequence execution returns true, execute the endpoint
AddressEndpoint.send()
AbstractEndpoint.send()
If message needs to build at this level, call the RelayUtils.build() method
Axis2SynapseEnvironment.send()
AxisSender.sendOn()
Axis2FlexibleMEPClient.send()
Create OperationClient and register the callback to process the response (if any)
OperationClient.execute()
OutInAxisOperation.executeImpl()
Add the registered callback to the callback store with the messageID
AxisEngine.send()
PassThroughHttpSender.invoke()
————————————
When a response is received from the back end, it will be captured by the TargetHandler class and spawn a new ClientWorker thread to process the response and hand it over to the axis engine to process. AxisEngine will call the respective message receiver (in this case CallBackReceiver).
Response Path
AxisEngine.receive()
SynapseCallbackReceiver.receive()
SynapseCallbackReceiver.handleMessage()
If there is an error, pop the fault handler and set the fault parameters and execute the fault handler
If there are no errors or special cases, hand over the message to synapse environment
Axis2SynapseEnvironment.injectMessage()
Check if this response is for a proxy service or not and proceed
If this is for a proxy service, then check the fault handler and add that to fault stack
————————————
Execute outSequence
SequenceMediator.mediate()
AbstractListMediator.mediate()
RelayUtils.buildMessage()
DeferredMessageBuilder.getDocument()
SOAPBuilder.processDocument()
LogMediator.mediate()
SendMediator.mediate()
Axis2SynapseEnvironment.send()
Axis2Sender.sendBack()
AxisEngine.send()
PassThroughHttpSender.invoke()
After going through this article, it would be better if you can do some debugging on the synapse code.
Nice blog! Keep update AWS Online Training
ReplyDelete