This guide describe how to get the following scenario working using WSO2 ESB 4.0.2, WSO2 AS 4.1.2
and WSO2 MB 1.0.2.

Conventions:
$ESB_HOME - The location of unzipped ESB distribution
$MB_HOME - The location of unzipped MB distribution
$AS_HOME - The location of unzipped AS distribution

Scenario:
A http proxy(proxyA) will be publishing messages into a topic hosted on WSO2 MB. Following three
separate subscribes will pick the message from that topic.
1. A generic Java JMS client subscribed to the same topic.
2. A simple service that is deployed on WSO2 AS subscribed to the same topic.
3. A JMS proxy deployed on WSO2 ESB which subscribed to the same topic.

proxyA will be invoked periodically by a task so that the proxy will publish messages into the topic.

A separate client generated for the proxyA will be also given so that that the proxy can be invoked
separately using that client.

Requirements:
1. WSO2 ESB 4.0.2 - Get from http://wso2.org/downloads/esb
2. WSO2 MB 1.0.2 - Get from http://wso2.org/downloads/message-broker
3. WSO2 AS 4.1.2 - Get from http://wso2.org/downloads/appserver


Note: To run the three Carbon servers on the same machine change the offset ports value in two
Carbon products. A sample carbon.xml is given for each product

1. If you are using MB 1.0.2, replace $MB_HOME/repository/components/plugin/org.wso2.carbon.qpid.authorization-3.2.1.jar with the given
org.wso2.carbon.qpid.authorization-3.2.1.jar.

2. Start WSO2 MB. Go into $MB_HOME/bin and run wso2server.sh/bat. Following log can be seen on the
console
INFO {org.apache.qpid.server.Main} -  Qpid broker TCP port : 5673

Configuring WSO2 ESB as the message publisher and as a subscriber
-----------------------------------------------------------------
3. synapse_sample_251.xml is a configuration that has the proxy configuration similar proxyA
(StockQuoteProxy) above. It's a http proxy which will publish messages
into the topic on WSO2 MB. Note that that endpoint type is set to topic and the topic name is set to
'SimpleStockQuoteService' so that a SimpleStockQuoteService deployed on AS can listen on a topic with
the same name.

Also note that the java.naming.provider.url is set to repository/conf/esb-publish-jndi.properties.
This is the JNDI file used by WSO2 MB JMS client jars and need to drop into $ESB_HOME/repository/conf.

Make sure to make the necessary changes in the 'esb-publish-jndi.properties' according to the port in
#1.

There is another proxy definition on the same configuration 'SimpleStockQuoteService' which act as
a subscriber to the same topic. This proxy uses the topic connection factory definition defined
in the axis2.xml. This subscriber just logged and drop the message.

Replace $ESB_HOME/repository/samples/synapse_sample_251.xml with this sample config.

4. Uncomment JMS transport sender and listener in $ESB_HOME/repository/conf/axis2.xml.

5. Start WSO2 ESB with ./wso2esb-samples.sh -sn 251


Configuring SimpleStockQuoteService on AS as a subscriber
---------------------------------------------------------
6. Enable JMS transport listener in $AS_HOME/respoitory/conf/axis2.xml. A sample axis2.xml configuration
is attached.

7. Also drop the 'as-subscribe-jndi.properties' into $AS_HOME/repository/conf. Make sure the property
 file is properly fixed for your server ports.

8. Go to $ESB_HOME/samples/axis2Server/src/SimpleStockQuoteService and type ant. This will create the
SimpleStockQuoteService.aar in $ESB_HOME/samples/axis2Server/repository/services.

9. Copy the above SimpleStockQuoteService.aar into $AS_HOME/repository/deployment/server/axis2services.

10. Go to $AS_HOME/bin and start the server using wso2server.sh

Configuring the sample generic JMS client as a subscriber
---------------------------------------------------------
11. Go to jms-client folder and invoke the client as follows.
ant sub -Dcarbon_home=$CARBON_HOME

You'll need to change the $CARBON_HOME environment variable to suite your environment.

Invoking the publisher
----------------------
12. Now we have a publisher and a three subscribers that are subscribes to the same topic. It's time to
invoke the publisher. Invoke the client to send a message to the proxy.

Go to $ESB_HOME/samples/axis2Client and,

ant stockquote -Daddurl=http://localhost:8280/services/StockQuoteProxy -Dmode=placeorder -Dsymbol=MSFT

You will see followings.

ESB log:
[2011-11-22 14:06:25,457]  INFO - LogMediator To: , WSAction: "urn:placeOrder", SOAPAction: "urn:placeOrder", MessageID: ID:db8b9de0-f9d4-3d8b-afa8-219623e151c7, Direction: request, Envelope:
 <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
 <soapenv:Body>
 <soapenv:Envelope>
 <soapenv:Body>
 <m0:placeOrder xmlns:m0="http://services.samples">
 <m0:order><m0:price>76.68217969163723</m0:price><m0:quantity>9879</m0:quantity>
 <m0:symbol>MSFT</m0:symbol></m0:order></m0:placeOrder></soapenv:Body></soapenv:Envelope>
 </soapenv:Body>
 </soapenv:Envelope>

AS log:
Tue Nov 22 14:06:25 IST 2011 samples.services.SimpleStockQuoteService  :: Accepted order #1 for : 9879 stocks of MSFT at $ 76.68217969163723

JMS client:

received : <?xml version='1.0' encoding='UTF-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><m0:placeOrder xmlns:m0="http://services.samples"><m0:order><m0:price>147.2348076830529</m0:price><m0:quantity>8533</m0:quantity><m0:symbol>MSFT</m0:symbol></m0:order></m0:placeOrder></soapenv:Body></soapenv:Envelope>


Generating a client for the publisher proxy
-------------------------------------------
You can generate a client for the Publisher proxy by logging into the service dashboard of the publisher
proxy. The generate client option will generate a client stub for you. You can compile the client using
maven build script(pom.xml) file that's available in the generated zip file. This will generate a client stub which
can be used in your actual client.

A publisher SOAP client
-----------------------
Go to the SOAP client folder soap-client and invoke the client using given ant build file. You need to
pass the $CARBON_HOME param according to your path
ant soapjmsclient -Dsymbol=IBM -DtopicName=SimpleStockQuoteService -Dcarbon_home=$CARBON_HOME
