How to trace inside the clone mediator and enable statistics and tracing for dynamic sequences

Trace inside the clone mediator and  enable statistics and tracing for dynamic sequences in WSO2 ESB

Here in this article i will try to brefly describe how to use WSO2 ESB samples and how to trace inside clone mediator.

You can download WSO2 ESB from here
http://wso2.com/products/enterprise-service-bus/

Starting the WSO2 ESB
Goto /bin folder run following command for ubuntu
> sh wso2server.sh
Run with sample here 0 is sample number
>sh wso2esb-samples.sh -sn 0

Log in to ESB as admin and
Goto Home> Configure > Logging > Service Bus Configuration by Clicking on source view. Then you will see synapse configuration source view.
Add following sequence to esb Configuration.


<sequence name="main" trace="enable" statistics="enable">
        <in>
            <clone>
                <target>
                    <sequence>
                        <log/>
                        <property name="a" value="a" scope="default"/>
                        <drop/>
                    </sequence>
                </target>
                <target>
                    <sequence>
                        <log/>
                        <property name="b" value="B" scope="default"/>
                        <drop/>
                    </sequence>
                </target>
            </clone>
        </in>
        <out>
            <send/>
        </out>
    </sequence>


As you can see here this will enable logs inside clone mediator. This will clone message and then add property a and b then drop the message.

Starting the Sample Apache Axis2 Server
Here we are using a standalone Apache Axis2 Web services engine(bundled with your ESB distribution) as the server
user@host:~/wso2esb/samples/axis2Server/src/SimpleStockQuoteService$ ant

now We have to start axis2server. Goto directory wso2esb-3.0.1/samples/axis2Server and type following command
wso2esb-3.0.1/samples/axis2Server$ sh axis2server.sh

To run sample client and send request to server goto folder wso2esb-3.0.1/samples/axis2Client and type following command
ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/

When you goto logs you will find logs related to 2 sequences inside clone mediator.See following logs
2012-02-29 14:43:12,029 [-] [HttpServerWorker-17] DEBUG Axis2SynapseEnvironment Injecting MessageContext for asynchronous mediation using the : Anonymous Sequence
2012-02-29 14:43:12,029 [-] [SynapseWorker-9] DEBUG PropertyMediator Setting property : a at scope : default to : a (i.e. constant : a)
2012-02-29 14:43:12,029 [-] [SynapseWorker-9] DEBUG PropertyMediator End : Property mediator
2012-02-29 14:43:12,030 [-] [SynapseWorker-10] DEBUG SequenceMediator Start : Sequence
2012-02-29 14:43:12,030 [-] [SynapseWorker-9] DEBUG DropMediator Start : Drop mediator
2012-02-29 14:43:12,030 [-] [SynapseWorker-9] DEBUG DropMediator End : Drop mediator
2012-02-29 14:43:12,030 [-] [HttpServerWorker-17] DEBUG CloneMediator End : Clone mediator
2012-02-29 14:43:12,030 [-] [SynapseWorker-9] DEBUG SequenceMediator End : Sequence
2012-02-29 14:43:12,030 [-] [SynapseWorker-10] DEBUG SequenceMediator Sequence :: mediate()



How to Load Balance across Cluster (setup WSO2 Load Balancer)

How to setup WSO2 Load Balancer

Load balancing is a key concern in a Platform-as-a-Service (PaaS) or a middleware platform deployed on the Cloud. An Elastic Load Balancer (ELB), in addition to carrying out its functionality in load balancing, is also responsible for monitoring the load & starting up new worker nodes or terminating existing worker nodes, depending on the load. An ideal use case of the Load Balancer is WSO2 StratosLive, where the service instances are fronted with the load balancers and the system scales automatically as the service gets more web service calls.  Here in this article we will see how to configure WSO2 Load Balancer Balance to use with Application server cluster

You can download WSO2 Application server from here http://wso2.com/products/application-server/
You can download WSO2 Load Balancer from here https://wso2.org/projects/load-balancer


1.Configure Application Server Cluster
Edit  mgt-transports.xml file as follows
Uncomment the HTTP proxy port in this file. The HTTP proxy port has to be set to port 80.

  
  1. <transport name="http" class="org.wso2.carbon.server.transports.http.HttpTransport">
  2.         <parameter name="protocol">HTTP_11_NIO</parameter>
  3.         <parameter name="port">${Ports.ServletTransports.HTTP}</parameter>
  4.         <parameter name="proxyPort">80</parameter>
  5.         <parameter name="maxHttpHeaderSize">8192</parameter>
  6.         <parameter name="acceptorThreadCount">2</parameter>
  7.         <parameter name="maxThreads">250</parameter>
  8.         <parameter name="minSpareThreads">50</parameter>
  9.         <parameter name="disableUploadTimeout">false</parameter>
  10.         <parameter name="connectionUploadTimeout">120000</parameter>
  11.         <parameter name="maxKeepAliveRequests">200</parameter>
  12.         <parameter name="acceptCount">200</parameter>
  13.         <parameter name="server">WSO2 Carbon Server</parameter>
  14.         <parameter name="compression">on</parameter>
  15.         <parameter name="compressionMinSize">2048</parameter>
  16.         <parameter name="noCompressionUserAgents">gozilla, traviata</parameter>
  17.         <parameter name="compressableMimeType">
  18.             text/html,text/javascript,application/x-javascript,application/javascript,
    application/xml,text/css,application/xslt+xml,text/xsl,image/gif,image/jpg,image/jpeg
  19.         </parameter>
  20.     </transport>
  21.     <transport name="https" class="org.wso2.carbon.server.transports.http.HttpTransport">
  22.         <parameter name="protocol">HTTPS_11_NIO</parameter>
  23.         <parameter name="port">${Ports.ServletTransports.HTTPS}</parameter>
  24.        <parameter name="proxyPort">443</parameter>
  25.         <parameter name="sslProtocol">TLS</parameter>
  26.         <parameter name="maxHttpHeaderSize">8192</parameter>
  27.         <parameter name="acceptorThreadCount">2</parameter>
  28.         <parameter name="maxThreads">250</parameter>
  29.         <parameter name="minSpareThreads">50</parameter>
  30.         <parameter name="enableLookups">false</parameter>
  31.         <parameter name="disableUploadTimeout">false</parameter>
  32.         <parameter name="connectionUploadTimeout">120000</parameter>
  33.         <parameter name="maxKeepAliveRequests">200</parameter>
  34.         <parameter name="acceptCount">200</parameter>
  35.         <parameter name="server">WSO2 Carbon Server</parameter>
  36.         <parameter name="clientAuth">false</parameter>
  37.         <parameter name="compression">on</parameter>
  38.         <parameter name="compressionMinSize">2048</parameter>
  39.         <parameter name="noCompressionUserAgents">gozilla, traviata</parameter>
  40.         <parameter name="compressableMimeType">
  41.             text/html,text/javascript,application/x-javascript,application/javascript,
     application/xml,text/css,application/xslt+xml,text/xsl,image/gif,image/jpg,image/jpeg
  42.         </parameter>
  43.         <parameter name="keystoreFile">
  44.             ${carbon.home}/repository/resources/security/wso2carbon.jks
  45.         </parameter>
  46.         <parameter name="keystorePass">wso2carbon</parameter>
  47.     </transport>


Edit carbon.xml In this file, we have to specify the Host of the App Server
   
<HostName>appserver.cloud-test.wso2.com</HostName>


Edit axis2.xml
In the axis2.xml file, you have to enable the clustering.
   
  1. <clustering class="org.apache.axis2.clustering.tribes.TribesClusteringAgent" enable="true">
  2.         <parameter name="AvoidInitiation">true</parameter>
  3.         <parameter name="membershipScheme">wka</parameter>
  4.         <parameter name="domain">wso2.as.domain</parameter>
  5.         <parameter name="synchronizeAll">true</parameter>
  6.         <parameter name="maxRetries">10</parameter>
  7.         <parameter name="mcastAddress">228.0.0.4</parameter>
  8.         <parameter name="mcastPort">45564</parameter>
  9.         <parameter name="mcastFrequency">500</parameter>
  10.         <parameter name="memberDropTime">3000</parameter>
  11.         <parameter name="localMemberPort">4100</parameter>
  12.         <parameter name="preserveMessageOrder">true</parameter>
  13.         <parameter name="atmostOnceMessageSemantics">true</parameter>
  14.         <parameter name="properties">
  15.             <property name="backendServerURL" value="https://${hostName}:${httpsPort}/services/"/>
  16.             <property name="mgtConsoleURL" value="https://${hostName}:${httpsPort}/"/>
  17.         </parameter>
  18.         <members>
  19.             <member>
  20.                 <hostName>appserver.cloud-test.wso2.com</hostName>
  21.                 <port>4000</port>
  22.             </member>
  23.         </members>

Keep rest of this xml file as it is.


2.Configure Load Balancer
Configuring the Load Balancer Cluster

locate the transportReceiver entries for the HTTP & HTTPS ports and change them to port 80 & 443 respectively. The relevant XML segments are shown below.
  
  1. <transportReceiver name="http" class="org.apache.synapse.transport.nhttp.HttpCoreNIOListener">
  2.         <parameter name="port" locked="false">80</parameter>
  3.         <parameter name="non-blocking" locked="false">true</parameter>
  4.         <!--parameter name="bind-address" locked="false">hostname or IP address</parameter-->
  5.         <!--parameter name="WSDLEPRPrefix" locked="false">https://apachehost:port/somepath</parameter-->
  6.         <parameter name="httpGetProcessor" locked="false">org.wso2.carbon.transport.nhttp.api.NHttpGetProcessor</parameter>
  7.     </transportReceiver>
  8.     <!-- the non blocking https transport based on HttpCore + SSL-NIO extensions -->
  9.     <transportReceiver name="https" class="org.apache.synapse.transport.nhttp.HttpCoreNIOSSLListener">
  10.         <parameter name="port" locked="false">443</parameter>
  11.         <parameter name="non-blocking" locked="false">true</parameter>
  12.         <!--parameter name="bind-address" locked="false">hostname or IP address</parameter-->
  13.         <!--parameter name="WSDLEPRPrefix" locked="false">https://apachehost:port/somepath</parameter-->
  14.         <parameter name="httpGetProcessor" locked="false">org.wso2.carbon.transport.nhttp.api.NHttpGetProcessor</parameter>
  15.         <parameter name="keystore" locked="false">
  16.             <KeyStore>
  17.                 <Location>repository/resources/security/wso2carbon.jks</Location>
  18.                 <Type>JKS</Type>
  19.                 <Password>wso2carbon</Password>
  20.                 <KeyPassword>wso2carbon</KeyPassword>
  21.             </KeyStore>
  22.         </parameter>
  23.         <parameter name="truststore" locked="false">
  24.             <TrustStore>
  25.                 <Location>repository/resources/security/client-truststore.jks</Location>
  26.                 <Type>JKS</Type>
  27.                 <Password>wso2carbon</Password>
  28.             </TrustStore>
  29.         </parameter>
  30.         <!--<parameter name="SSLVerifyClient">require</parameter>
  31.             supports optional|require or defaults to none -->
  32.     </transportReceiver>



Edit loadbalancer.xml to map the HTTP host to the clustering domain.Add following segment to services section
  
  1. <services>
  2.         <defaults>
  3.             <property name="availabilityZone" value="us-east-1c"/>
  4.             <property name="securityGroups" value="default-2011-02-23"/>
  5.             <property name="instanceType" value="m1.large"/>
  6.             <property name="minAppInstances" value="1"/>
  7.             <property name="maxAppInstances" value="5"/>
  8.             <property name="queueLengthPerNode" value="400"/>
  9.             <property name="roundsToAverage" value="10"/>
  10.             <property name="instancesPerScaleUp" value="1"/>
  11.             <property name="messageExpiryTime" value="60000"/>
  12.         </defaults>
  13.         <service>
  14.             <hosts>
  15.                 <host>appserver.cloud-test.wso2.com</host>
  16.             </hosts>
  17.             <domain>wso2.as.domain</domain>
  18.         </service>
  19.     </services>


Please note that appserver.cloud-test.wso2.com is mapped to 127.0.0.1 in my machine by changing /etc/hosts entries.Also change carbon.xml file located in appserver repository/conf by adding following entry.
   
<HostName>appserver.cloud-test.wso2.com</HostName>




Now you have to up and run load balancer product first then run appserver product. You will see following message in loadbalancer log when appserver joins to the load balance cluster.
[2012-02-23 17:34:12,048]  INFO - RpcMembershipRequestHandler Received JOIN message from 10.200.2.85:4100(wso2.as.domain)
[2012-02-23 17:34:12,052]  INFO - MembershipManager Application member 10.200.2.85:4100(wso2.as.domain) joined group wso2.as.domain
[2012-02-23 17:34:23,062]  INFO - DefaultGroupManagementAgent Application member Host:10.200.2.85, Port: 4100, HTTP:9763, HTTPS:9443, ACTIVE:true joined application cluster

Now you can invoke Application server by typing https://appserver.cloud-test.wso2.com:443/carbon/ URL in browser. So you will see the logs related to the requested page in loadbalancer logs.
To remove autoscale you have to remove autoscaler.xml file from wso2lb-1.0.2/repository/deployment/server/synapse-configs/default/tasks folder. Also remove autoscalein and autoscaleout configurations from main.sequence(from main.xml file located in wso2lb-1.0.2/repository/deployment/server/synapse-configs/default/sequences).

How to use SQS Client to invoke SQS service in message broker

  1. Create SQS Client Code

    Generate code from wsdltojava tool. See following figure





















    Unzip given zip file from wsdl to java tool and open it with some IDE(eclipse or idea). Use following command to create idea project
    mvn idea:idea

    Build project with maven using the command
    mvn clean install

    Then we have to add necessary jars to class path
    First run ant command inside your message broker product as follows
    packs/wso2mb-1.0.2/bin$ ant
    Then this will copy jars to repository/lib folder inside your pack. We have to add those jars to class path of created project(Eclipse or idea)















    Then build your project using ide. If it complaints about axiom or rampart jars please remove them from the class path(remove any axiom jars except version 1.2.11.wso2v1)

    Then add SQSClient java code to project. We must run the main method in this class in order to run the SQS operations. Code is available at following url http://wso2.org/project/message-broker/1.0.2/docs/samples/sqs_soap_client.html
    Change the "accessKey" and the "secretAccessKey" in sqsClient.java code to the keys which can be found at "Home > Manage> Message Boxes(SQS)> Access Keys" of wso2mb server














  1. Run sqsClient java code and you will see following output in terminal
    createQueueResponse.getCreateQueueResult().getQueueUrl() = http://localhost:9763/services/MessageQueue/admin/Shared
    createQueueResponse.getCreateQueueResult().getQueueUrl() = http://localhost:9763/services/MessageQueue/admin/Shared
    message_type0.getBody() = TEST MESSAGE
    message_type0.getBody() = TEST MESSAGE
    message_type0.getBody() = TEST MESSAGE
    message_type0.getBody() = TEST MESSAGE
    message_type0.getBody() = TEST MESSAGE
    message_type0.getBody() = TEST MESSAGE
    message_type0.getBody() = TEST MESSAGE
    message_type0.getBody() = TEST MESSAGE
    message_type0.getBody() = TEST MESSAGE
    message_type0.getBody() = TEST MESSAGE
    createQueueResponse.getCreateQueueResult().getQueueUrl() = http://localhost:9763/services/MessageQueue/admin/Shared
    createQueueResponse.getCreateQueueResult().getQueueUrl() = http://localhost:9763/services/MessageQueue/admin/Shared

Empowering the Future of API Management: Unveiling the Journey of WSO2 API Platform for Kubernetes (APK) Project and the Anticipated Alpha Release

  Introduction In the ever-evolving realm of API management, our journey embarked on the APK project eight months ago, and now, with great a...