By Yogananda

“Remain calm, serene, always in command of yourself. You will then find out how easy it is to get along.”
-By Yogananda

Thursday, December 19, 2013

PayloadFactory Vs Enrich Mediator in WSO2 ESB



When you need to customize the payload of request or a response in WSO2 ESB, then here is the way to go. You can use PayloadFactory mediator to replace the payload with the different payload or you can use enrich mediator to modify the existing payload.

  • The following steps will explain how can a payload be replaced with a different payload using PayloadFactory mediator:


<property name="id" expression="//id" scope="default" type="STRING"/>
<property name="name" expression="//name" scope="default" type="STRING"/>

<payloadFactory media-type="xml">
        <format>
            <m:response xmlns:m="http://services.samples">
                <m:customer>
                    <m:id>$1</m:id>
                    <m:name>$2</m:name>
                </m:customer>
            </m:response>
        </format>
        <args>
            <arg evaluator="xml" expression="$ctx:id"/>
            <arg evaluator="xml" expression="$ctx:name"/>
        </args>
    </payloadFactory>

Where in the argument, the id and name are set using the message context. From the request or response, these id and name can be parsed through the xpath and set it as a property as above.


  • The following steps will explain how can a payload be replaced with a different payload using Enrich mediator:


<property name="id" expression="//id" scope="default" type="STRING"/>
<property name="name" expression="//name" scope="default" type="STRING"/>

<enrich>
            <source type="inline">
                <response >
                <customer>
                    <id>xxx</id>
                    <name>xxxx</name>
                </customer>
            </response>
            </source>
            <target type="body"/>
 </enrich>
<enrich>
            <source type="property" clone="true" property="id"/>
            <target xpath="//s:response/s:customer/s:id" xmlns:s="http://ws.apache.org/ns/synapse"/>
</enrich>
 <enrich>
            <source type="property" clone="true" property="message"/>
            <target xpath="//s:response/s:customer/s:name" xmlns:s="http://ws.apache.org/ns/synapse"/>
</enrich>

In this case, the first enrich will replace the body with the specified payload. Then the second and third enrich will replace the values of the element in the body using the available property.
       






Monday, February 18, 2013

Worker-Manager separation with two ELB's

The latest release of WSO2 products which were based on carbon 4.0.0 supports worker-manger separation. In this post, you can find out how to configure worker-manager with two ELB's with single cluster and how it can be extended to another deployment. This patterns is clearly explained in Afkham Azeez's blog.

Worker-Manager clustering with two ELB's and one worker/manager cluster


I have configured every instance in different machine. The configuration can be found as following:

ELB-mgt
=========
repository/conf/loadbalancer.conf

esb {
hosts mgt.esb.cloud-test.wso2.com;
domains {
wso2.esb.domain {
sub_domain worker;
tenant_range *;
}
}
}

repository/conf/carbon.xml

<MgtHostName>elb.mgt.wso2.com</MgtHostName>

Then you have to have the relevant entry in the /etc/hosts for elb.mgt.wso2.com.


ELB-worker
===========
repository/conf/loadbalancer.conf
esb {
hosts esb.cloud-test.wso2.com;
domains {
wso2.esb.domain {
sub_domain worker;
tenant_range *;
}
}
}


repository/conf/carbon.xml

<MgtHostName>elb.worker.wso2.com</MgtHostName>

Then you have to have the relevant entry in the /etc/hosts for elb.worker.wso2.com.

I have assumed here that port offset of both ELB's are kept as default and they are running in different machine. Default ELB's transport port https:8243, http:8280


Worker-cluster
==============

All worker nodes can be configured as in (http://docs.wso2.org/wiki/display/ELB203/Setup+ELB+with+WSO2+ESB) for clustering and proxy set up. Also, add the relevant entries to /etc/hosts
in addition to the configuration, you will have to add the following to all worker node as like management node (can find the place in documentation).

repository/conf/axis2/axis2.xml

<property name="port.mapping.8280" value="9764"/>
<property name="port.mapping.8243" value="9444"/>

9764, 9444 can be veried according to your port offset of servlet transport. 8280, 8283 are ELB's transport. If two ELB for one cluster, then both should be kept in the same transport port.

Special node which will be manager and worker
==========================================
Have to configure like above worker node cluster and in addition to that need to add

repository/conf/carbon.xml

<MgtHostName>mgt.esb.cloud-test.wso2.com</MgtHostName>


repository/conf/axis2/axis2.xml

Instead of one member, need to add two ELB as well known memebers.

<members>
<member>
<hostName>elb.mgt.wso2.com</hostName>
<port>4000</port>
</member>
<member>
<hostName>elb.worker.wso2.com</hostName>
<port>4000</port>
</member>
</members>

repository/conf/axis2.xml.

<parameter name="WSDLEPRPrefix" locked="false">http://esb.cloudtest.wso2.com:8280</parameter>


/etc/hosts of special node should include
.
<ip of ELB worker> esb.cloud-test.wso2.com
<ip of ELB managee> mgt.esb.cloud-test.wso2.com
<ip of ELB worker> elb.worker.wso2.com
<ip of ELB manager> elb.mgt.wso2.com

Single cluster with one ELB where one node worker/manager and accessible directly
==================================================================



All workers need to configure as stated in the documentation.

Special Node :

As stated in the above setup for special node, you will have to follow up,

adding only one member as a well known member as following:

<members>
<member>
<hostName>elb.worker.wso2.com</hostName>
<port>4000</port>
</member>
</members>

removing the proxy port in repository/conf/tomcat/catalina-server.xml and keep other configurations as it is.

All the other configuration should be kept as previous setup manager node. Now you can eliminate the manager ELB and work on this setup accessing management console directly via https://mgt.esb.cloud-test.wso2:9444 (servlet transport port) and worker requests can be served via https://esb.cloud-test.wso2:8243 via ELB.

Also, add the /etc/hosts as similar as above setup to the special node machine.

References
========

1. http://blog.afkham.org/2012/08/separation-of-worker-management-nodes.html
2. http://charithaka.blogspot.com/2012/09/setting-up-minimum-deployment-of-wso2.html