Skip to main content

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.














Comments

Post a Comment

Popular posts from this blog

WSO2 ESB tuning performance with threads

I have written several blog posts explaining the internal behavior of the ESB and the threads created inside ESB. With this post, I am talking about the effect of threads in the WSO2 ESB and how to tune up threads for optimal performance. You can refer [1] and [2] to understand the threads created within the ESB. [1] http://soatutorials.blogspot.com/2015/05/understanding-threads-created-in-wso2.html [2] http://wso2.com/library/articles/2012/03/importance-performance-wso2-esb-handles-nonobvious/ Within this blog post, I am discussing about the "worker threads" which are used for processing the data within the WSO2 ESB. There are 2 types of worker threads created when you start sending the requests to the server 1) Server Worker/Client Worker Threads 2) Mediator Worker (Synapse-Worker) Threads Server Worker/Client Worker Threads These set of threads will be used to process all the requests/responses coming to the ESB server. ServerWorker Threads will be used to pr

How puppet works in your IT infrstructure

What is Puppet? Puppet is IT automation software that helps system administrators manage infrastructure throughout its lifecycle, from provisioning and configuration to orchestration and reporting. Using Puppet, you can easily automate repetitive tasks, quickly deploy critical applications, and proactively manage change, scaling from 10s of servers to 1000s, on-premise or in the cloud. How the puppet works? It works like this..Puppet agent is a daemon that runs on all the client servers(the servers where you require some configuration, or the servers which are going to be managed using puppet.) All the clients which are to be managed will have puppet agent installed on them, and are called nodes in puppet. Puppet Master: This machine contains all the configuration for different hosts. Puppet master will run as a daemon on this master server. Puppet Agent: This is the daemon that will run on all the servers, which are to be managed using p

How to configure timeouts in WSO2 ESB to get rid of client timeout errors

WSO2 ESB has defined some configuration parameters which controls the timeout of a particular request which is going out of ESB. In a particular  scneario, your client sends a request to ESB, and then ESB sends a request to another endpoint to serve the request. CLIENT->WSO2 ESB->BACKEND The reason for clients getting timeout is that ESB timeout is larger than client's timeout. This can be solved by either increasing the timeout at client side or by decreasing the timeout in ESB side. In any of the case, you can control the timeout in ESB using the below properties. 1) Global timeout defined in synapse.properties (ESB_HOME\repository\conf\) file. This will decide the maximum time that a callback is waiting in the ESB for a response for a particular request. If ESB does not get any response from Back End, it will drop the message and clears out the call back. This is a global level parameter which affects all the endpoints configured in ESB. synapse.global_timeout_inte