Wednesday, December 9, 2015

How to use send mediator in WSO2 ESB

Send mediator is used to send current message to a particular given endpoint or basically out of the synapse code. If you are not using any endpoint and also using send mediator then same message is send to the initiator because it also makes a copy of the current message.

To send a message to a particular destination this mediator must be used even you want same message as a reply.


When no Address:

<send/> syntax is used when no endpoint is there, if this is written in out sequence of the service, means same message will be replied back to the requester.

With Endpoint Address:

   (endpointref | endpoint)+

Above syntax will send current message to defined endpoint and same message can be used for the further logic.

With Service Chaining:

<send receive="ManagerDetailSEQ">
    <endpoint key=" ManagerDetailsEPR"/>

Above syntax is used when we need to have service chaining in our composite service logic. Above syntax shows that current message will be directed to the ManagerDetails endpoint, for which a particular key has been defined and ManagerDetailSEQ will be executed. So message can be captured for the logic in this ManagerDetailSEQ sequence.

Use from UI Configuration:

Send mediator can be found inside of Core option category as mentioned in below image.

One you click on the send mediator, you will get the below screen in which you have to provide some information.

None: As already mentioned above, if you don’t select anything then it means same message will be replied back to initiator.

Define Inline: In this option you can add a defined endpoint, there is an Add option appears in which you can add an endpoint in which you have to send the message.

Pick from Registry: In this option you can choose an endpoint from governance registry.

Receiving sequence Type: Just after the sending the message to the endpoint, which sequence you want to execute, you can define.

In the latest version you can get one more option like mentioned below:

Build Message before sending:

If you put Yes in it, it stores the message in memory and then send to endpoint otherwise does not store. To performance point of view select it to NO.


    <proxy name="DSS_EmployeeDetailDataServiceProxy" transports="http" startOnLoad="true" trace="disable" statistics="enable">
        <target inSequence="DSS_EmployeeDetailDataService_IN" outSequence="CommonSequence_OUT" faultSequence="DSS_EmployeeDetailDataService_Fault"/>
        <publishWSDL key="DSS_EmployeeDetailDataService_wsdl"/>
                           <localEntry key="DSS_EmployeeDetailDataService_wsdl" src="file:repository/conf/employee/EmployeeDetailDataService.wsdl"/>
                           <sequence name="DSS_EmployeeDetailDataService_IN">
        <log level="full"/>
        <script language="js">java.lang.Thread.sleep(50000);</script>
        <cache id="GetEmpDetailCache" scope="per-host" collector="false" hashGenerator="org.wso2.caching.digest.DOMHASHGenerator" timeout="20" maxMessageSize="500">
            <implementation type="memory" maxSize="1000"/>
            <endpoint key="DSS_EmployeeDetailDataService_EPR"/>
                           <endpoint name="DSS_EmployeeDetailDataService_EPR">
        <address uri="">
                            <sequence name="CommonSequence_OUT">
        <log level="full"/>
        <cache id="GetEmpDetailCache" scope="per-host" collector="true"/>