Connect WSO2 ESB with WSO2 MB


WSO2 Enterprise Service Bus (WSO2 ESB) and WSO2 Message Broker (WSO2 MB) plays very important role in opensource Enterprise Application Integration. With WSO2 ESB, WSO2 MB can be used for 2 different tasks.

1. JMS Endpoint

2. Message Store

In here I’m talkng about connecting WSO2 ESB with WSO2 MB 1.0.2 as a JMS endpoint. It will also shows how WSO2 ESB exhibits Message Broker EAI pattern. Basically it does is decoupling messages from sender and receiver. Senders message is put into a Message Broker and any receiver who interested in those messages can consume. In following example you can see how WSO2 ESB  works with WSO2 Message Broker (WSO2 MB version 1.0.2) Queue to do that. If you want to add more receivers you can use Topics provided in WSO2 MB in a similar way.


Setting up WSO2 MB

  • Change default virtual host to “carbon” inside wso2mb-1.0.2/repository/conf/advancedqpid-virtualhosts.xml file.
  • Start WSO2 MB by executing (or wso2server.bat in Windows) file in wso2mb-1.0.2/bin

Setting up WSO2 ESB

  • Copy geronimo-jms_1.1_spec-1.1.0.wso2v1.jar and qpid-client-0.11.0.wso2v2.jar from wso2mb-1.0.2/client-lib to wso2esb-4.5.1/repository/components/lib
  • Enable jms transport Receivers and Senders by uncomment related sections as given below in file wso2esb-4.5.1/repository/conf/axis2/axis2.xml
<transportReceiver name="jms" class="org.apache.axis2.transport.jms.JMSListener">
 <!--Only Enabled settings related to Queue since the sample here only uses a queue-->
 <parameter name="myQueueConnectionFactory" locked="false">
 <parameter name="java.naming.factory.initial" locked="false">org.apache.qpid.jndi.PropertiesFileInitialContextFactory</parameter>
 <parameter name="java.naming.provider.url" locked="false">repository/conf/</parameter>
 <parameter name="transport.jms.ConnectionFactoryJNDIName" locked="false">QueueConnectionFactory</parameter>
 <parameter name="transport.jms.ConnectionFactoryType" locked="false">queue</parameter>
 <parameter name="default" locked="false">
 <parameter name="java.naming.factory.initial" locked="false">org.apache.qpid.jndi.PropertiesFileInitialContextFactory</parameter>
 <parameter name="java.naming.provider.url" locked="false">repository/conf/</parameter>
 <parameter name="transport.jms.ConnectionFactoryJNDIName" locked="false">QueueConnectionFactory</parameter>
 <parameter name="transport.jms.ConnectionFactoryType" locked="false">queue</parameter>
<transportSender name="jms" class="org.apache.axis2.transport.jms.JMSSender"/>
  • Set wso2esb-4.5.1/repository/conf/ file as follows.
#Need change QueueConnection factory as follows
connectionfactory.QueueConnectionFactory = amqp://admin:admin@clientID/carbon?brokerlist='tcp://localhost:5673'

# register some queues in JNDI using the form
# queue.[jndiName] = [physicalName]
destination.myqueue=destinationMyQueue; {create:always}

# register some topics in JNDI using the form - Commented since this sample is not going to use Topics
# topic.[jndiName] = [physicalName]
#topic.MyTopic = example.MyTopic
  • Now start WSO2 ESB by executing (wso2server.bat in Windows) inside wso2esb-4.5.1/bin
  • Change the configuration of ESB to the following.
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="">
 <proxy name="StockQuoteProxy"
 <!-- Send message to WSO2 MB -->
 <address uri="jms:/myqueue?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&amp;java.naming.factory.initial=org.apache.qpid.jndi.PropertiesFileInitialContextFactory&amp;java.naming.provider.url=repository/conf/;transport.jms.DestinationType=queue"/>
 <property name="OUT_ONLY" value="true"/>
 <property name="FORCE_SC_ACCEPTED" value="true" scope="axis2"/>
 <property name="transport.jms.ContentTypeProperty"
 <property name="TRANSPORT_HEADERS" scope="axis2" action="remove"/>
 <sequence name="fault">
 <log level="full">
 <property name="MESSAGE" value="Executing default "fault" sequence"/>
 <property name="ERROR_CODE" expression="get-property('ERROR_CODE')"/>
 <property name="ERROR_MESSAGE" expression="get-property('ERROR_MESSAGE')"/>
 <sequence name="main">

The JMS URL is made up of:


Look for a JNDI entry “myqueue”(see jndi properties above)

?   Separator indicating extra attributes


Look up ConnectionFactory in JNDI with name QueueConnectionFactory

&            Separator (this will convert to ‘&’)


Use the Qpid properties-based JNDI

&             Another separator


Look in repository/conf/ for the JNDI properties file

Now you  can send messages from sample/axis2Clint as follows to the ESB proxy and they will get stored in WSO2 MB.

ant stockquote -Dtrpurl=http://localhost:8280/services/StockQuoteProxy -Dsymbol=WSO2

The stored message can be consumed by any consumer who is keen on destinationMyQueue of WSO2 MB.


[1] WSO2 ESB –

[2] WSO2 MB –

[3] Introduction to Message Broker –

[4] Pub/Sub in SOA –


21 thoughts on “Connect WSO2 ESB with WSO2 MB

  1. WSO2 has launched the latest version of WSO2 MB 2.0.1. So above configuration needs few more changes as follows.
    In setting up MB you need to change ‘connectionString’ to : localhost:9161 in wso2mb-1.0.2/repository/conf/advancedqpid-virtualhosts.xml file.

    In setting up ESB you have to clear previous geronimo-jms_1.1_spec-1.1.0.wso2v1.jar and qpid-client-0.11.0.wso2v2.jar files from both /repository/components/lib & /repository/components/dropins
    Then copy; andes-client-0.13.wso2v4.jar
    FROM wso2mb-2.0.1/client-lib TO wso2esb/repository/components/lib folder.

    Comment the ESB previous jms transport reciver in axis2.xml
    and uncomment the jms transport receiver for MB 2.x.x in the same file.

    Change the following lines in as follows:
    connectionfactory.QueueConnectionFactory = amqp://admin:admin@clientID/carbon?brokerlist=’tcp://localhost:5673′

    # register some queues in JNDI using the form
    # queue.[jndiName] = [physicalName]

    In your ESB configuration endpoint should be changed as follows:

    Now you have configured WSO2 MB 2.0.1 as a endpoint for WSO2 ESB.

  2. Hi Buddhima,
    Awesome post, it realy help me, im was doing wrong…

    im trying to use a JMS Message Store, but im getting no erros and my messages dosnt get the queue…

    can u show, how to use a JMS Message Store?

    thank´s a lot man

  3. yeah im following this one, indeed this start everything,

    u talk about de .jars we need and about uncomment some files…

    i guess, everything u guys say i did…

    Message Store in Memory its working, part 1from wso2post, but JMS, dosnt.

    im using the same exalmple, just change the store and processor.

    My MessageStore look like this;




    my JNDI file at ESB_HOME/repository/conf

    # register some connection factories
    # connectionfactory.[jndiname] = [ConnectionURL]
    connectionfactory.TopicConnectionFactory = amqp://admin:admin@carbon/carbon?brokerlist=’tcp://localhost:5672′;
    connectionfactory.QueueConnectionFactory = amqp://admin:admin@carbon/carbon?brokerlist=’tcp://localhost:5672′;

    # register some queues in JNDI using the form
    # queue.[jndiName] = [physicalName]

    my Queue list at MB

    1. Hi Johanes,
      I’m not aware of the version of WSO2 MB you are using.
      So if it’s MB 2.0.1 or later , it uses Andes instead of Qpid. So “org.apache.qpid.jndi.PropertiesFileInitialContextFactory” should be changed as “org.apache.andes.jndi.PropertiesFileInitialContextFactory” (same thing mentioned in axis2.xml too)

      Another mistake is incorrect port number. ‘tcp://localhost:5672’ is wrong. This default value should be increased by the offset you set. Eg: if offset of WSO2 MB is 1, then ‘tcp://localhost:5673’.

      Thanks !

  4. Hi Buddhima,

    yes im using MB 2.0.0

    hell yeah its working now!!! i should use this config: “org.wso2.andes.jndi.PropertiesFileInitialContextFactory”

    about the mb port its realy 5672, i didnt change MB config, i did it on ESB 😉

    thank you so much!

  5. Hi Buddhima,

    I followed your article. I m using esb 4.5.1 and mb 2.0.0.

    Still m not able to make it work.

    I have kept mb on port 9443 and esb on 9445.

    But my esb starts at 8245 and m getting exception.

    Posting logs:

    TID: [0] [ESB] [2013-03-01 10:28:48,888] ERROR {org.wso2.carbon.event.core.internal.builder.EventBrokerHandler} – Can not create the event broker {org.wso2.carbon.event.core.internal.builder.EventBrokerHandler}
    org.wso2.carbon.event.core.exception.EventBrokerConfigurationException: Can not connect to the remote Qpid Service
    at org.wso2.carbon.event.core.internal.CarbonEventBrokerFactory.getEventBroker(
    at org.wso2.carbon.event.core.internal.builder.EventBrokerBuilder.createEventBroker(
    at org.wso2.carbon.event.core.internal.builder.EventBrokerHandler.startEventBroker(
    at org.wso2.carbon.event.core.internal.builder.EventBrokerBuilderDS.activate(
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(
    at java.lang.reflect.Method.invoke(
    at org.eclipse.equinox.internal.ds.model.ServiceComponent.activate(
    at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.activate(
    at org.eclipse.equinox.internal.ds.InstanceProcess.buildComponent(
    at org.eclipse.equinox.internal.ds.InstanceProcess.buildComponents(
    at org.eclipse.equinox.internal.ds.Resolver.getEligible(
    at org.eclipse.equinox.internal.ds.SCRManager.serviceChanged(
    at org.eclipse.osgi.internal.serviceregistry.FilteredServiceListener.serviceChanged(
    at org.eclipse.osgi.framework.internal.core.BundleContextImpl.dispatchEvent(
    at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(
    at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(
    at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEventPrivileged(
    at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEvent(
    at org.eclipse.osgi.internal.serviceregistry.ServiceRegistrationImpl.register(
    at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.registerService(
    at org.eclipse.osgi.framework.internal.core.BundleContextImpl.registerService(
    at org.eclipse.osgi.framework.internal.core.BundleContextImpl.registerService(
    at org.wso2.carbon.core.init.CarbonServerManager.initializeCarbon(
    at org.wso2.carbon.core.init.CarbonServerManager.removePendingItem(
    at org.wso2.carbon.core.init.PreAxis2ConfigItemListener.bundleChanged(
    at org.eclipse.osgi.framework.internal.core.BundleContextImpl.dispatchEvent(
    at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(
    at org.eclipse.osgi.framework.eventmgr.EventManager$
    Caused by: org.apache.axis2.AxisFault: Connection refused: connect
    at org.apache.axis2.AxisFault.makeFault(
    at org.apache.axis2.transport.http.HTTPSender.sendViaPost(
    at org.apache.axis2.transport.http.HTTPSender.send(
    at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(
    at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(
    at org.apache.axis2.engine.AxisEngine.send(
    at org.apache.axis2.description.OutInAxisOperationClient.send(
    at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(
    at org.apache.axis2.client.OperationClient.execute(
    at org.wso2.carbon.event.client.stub.generated.authentication.AuthenticationAdminServiceStub.login(
    … 31 more
    Caused by: Connection refused: connect
    at Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(
    at java.lang.reflect.Method.invoke(
    at org.apache.commons.httpclient.protocol.ReflectionSocketFactory.createSocket(
    at org.apache.commons.httpclient.protocol.SSLProtocolSocketFactory.createSocket(
    at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$
    at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(
    at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(
    at org.apache.commons.httpclient.HttpClient.executeMethod(
    at org.apache.axis2.transport.http.AbstractHTTPSender.executeMethod(
    at org.apache.axis2.transport.http.HTTPSender.sendViaPost(
    … 40 more
    TID: [0] [ESB] [2013-03-01 10:28:50,300] INFO {org.wso2.carbon.ui.internal.CarbonUIServiceComponent} – Mgt Console URL : {org.wso2.carbon.ui.internal.CarbonUIServiceComponent}
    TID: [0] [ESB] [2013-03-01 10:29:44,316] WARN {org.wso2.carbon.core.internal.StartupFinalizerServiceComponent} – Waiting for required OSGi services:, {org.wso2.carbon.core.internal.StartupFinalizerServiceComponent}
    TID: [0] [ESB] [2013-03-01 10:30:44,317] WARN {org.wso2.carbon.core.internal.StartupFinalizerServiceComponent} – Waiting for required OSGi services:, {org.wso2.carbon.core.internal.StartupFinalizerServiceComponent}
    TID: [0] [ESB] [2013-03-01 10:31:44,317] WARN {org.wso2.carbon.core.internal.StartupFinalizerServiceComponent} – Waiting for required OSGi services:

    why is it taking qpid instead of andes?

    please help.

    1. Hi Naveen,
      Please make sure that to clear previous geronimo-jms_1.1_spec-1.1.0.wso2v1.jar and qpid-client-0.11.0.wso2v2.jar files from both /repository/components/lib & /repository/components/dropins (If you tried with previous versions of WSO2 MB) and put necessary files as mentioned in my first comment.
      Hope you have made necessary Axis2 configurations correctly.
      Andes is derived from Qpid project. Thus Qpid specific things may still exist.
      Normally we start MB with a offset and point ESB which runs on default port to it, opposite to what you’ve done.
      Not sure about the problem with port. (May be ESB Management Console url)
      I forwarded your question to a member of MB team (Hasitha Abeykoon), and he gave those suggestions.
      This link will tell you more about configuring WSO2 ESB with WSO2 MB:

  6. Hi Buddhima,
    I have used two instances of WSO2 ESB 4.6 at port number 9443(esb1) and 9446(esb2) and also using Message Broker 2.0.1 at 9444. I am using this url as my tutorial : I have done the Queue to queue send recieve example using the above link. And everything is working fine. But the problem is when i post any message to esb1, it gets reflected to esb2 since esb2 is working as my subscriber. I want that message store should store that message passed on from esb1 and based on some event it should provide esb2 the messages sent by esb1. How to do this?

    1. Hi Roy,
      Did you have a look at Topics? Isn’t that the solution for your problem?
      Depending on the content of messages, ESB1 could direct messages to different Topics in MB. Then you can configure ESB2 to the required Topic and it’ll get only the required messages.
      Hope this will help you Roy 🙂

  7. Yes this is the approach that i have taken but the problem is i want to store my messages to message store and process it via message processor at the reciever side i.e esb2 but i am unable to implement the message store successfully to the proxy that has been provided in the url that i specified. I am struck at that part only. Not able to passs the message from esb1 to message store of esb2.

  8. Hi,
    I have two scenario’s that i have to achieve:
    Client 1 Sends the message to ESB -> ESB consumes the message and stores it into the queue -> End of Scenario1;
    This is done.
    Second Scenario is :
    Client 2 sends a request to ESB to get messages -> ESB gets the messages from the queue defined for Client 2 -> ESB sends back a pack of message that were present in the queue

    I am unable to do the second scenario?
    Please help me on this

    1. Hi Roy,
      As far as I can see, 2nd scenario is impossible to accomplish according to the proposed way.
      WSO2 ESB currently has only 2 ways of taking off messages from a Message store;
      1. Through a JMS proxy
      2. Using a Message Processor
      Non of them is able to trigger from a message.
      But, a possible way might be to write a Service to take messages from message store (hope you’re talking about MB, if so follow creating MB clients to read messages) and aggregate them (ESB aggregate mediator only aggregates response messages).
      So, you can expose the above Service to ESB through an Endpoint, and create a filter which sends only a certain type of messages to that Endpoint. Response of that Endpoint should be aggregated message (a pack of message that were present in the queue).
      Keep in mind that ESB is mainly for Message Mediation. Other services are optional.
      In here I expressed my personal opinion about the question you asked. You can contact WSO2 ESB team for more information.
      Thanks !

  9. How to achieve this scenario :
    I have message in MB’s queue. I have a proxy in which i have used a wsdl that has two operation
    OpenSession and ReadMessage. So at first i access the OpenSesssion, it returns me SessionID as response. I copy that SessionID. Now i access the ReadMessage Operation where in i am passing the sessionID as request and in return this operation will get the message from queue and show as response.
    Waiting for your help on this.
    Thanks in advance

    1. Hi Roy,
      Hope “I have a proxy in which i have used a wsdl that has two operation” means you have a service and its WSDL is used as proxy’s WSDL.
      There are 2 approaches.
      1. Using Send mediator you can first send the message to service to take SessionID, then by specifying a Receiving Sequence, you can do access ReadMessage. You may need some other mediators too. (Send mediator:
      2. Consider about Routing Slip EAI pattern (
      Hope those will help you 🙂

  10. but didn’t get how i can get message from queue of MB at my ReadMessage Operation.
    Basicallyy i am using filter mediators to check which operation has been invoked. If filter for OpenSession is true then it will provide me session Id as response and if filter for ReadMessage is true then it will fetch message from queue. So at this filter i am unable to write a code that can fetch data from queue of messagebroker.Please help me. Badly need to know how i can get message from queue on ReadMessage Filter when it is true.

  11. Hi Buddhima,

    Iam using WSO2 ESB 4.7.0 and WSO2 MB 2.2.0, ihave followed your post and configured my ESB and MSB.

    when am testing my proxy am facing an error as shown below

    JMSOutTransportInfo Could not get an initial context using {java.naming.provider.url=repository/conf/, java.naming.factory.initial=org.apache.qpid.jndi.PropertiesFileInitialContextFactory, transport.jms.DestinationType=queue, transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory}
    javax.naming.NoInitialContextException: Failed to create InitialContext using factory specified in hash table. [Root exception is java.lang.ClassNotFoundException: class org.apache.qpid.jndi.PropertiesFileInitialContextFactory not found]
    at org.wso2.carbon.context.internal.CarbonContextDataHolder$CarbonInitialJNDIContextFactoryBuilder.createInitialContextFactory(
    at javax.naming.spi.NamingManager.getInitialContext(
    at javax.naming.InitialContext.getDefaultInitCtx(
    at javax.naming.InitialContext.init(
    at javax.naming.InitialContext.(
    at org.apache.axis2.transport.jms.JMSOutTransportInfo.loadConnectionFactoryFromProperties(
    at org.apache.axis2.transport.jms.JMSOutTransportInfo.createJMSSender(
    at org.apache.axis2.transport.jms.JMSSender.sendMessage(
    at org.apache.axis2.transport.base.AbstractTransportSender.invoke(
    at org.apache.axis2.engine.AxisEngine.send(
    at org.apache.axis2.description.OutOnlyAxisOperationClient.executeImpl(
    at org.apache.axis2.client.OperationClient.execute(
    at org.apache.synapse.core.axis2.Axis2FlexibleMEPClient.send(
    at org.apache.synapse.core.axis2.Axis2Sender.sendOn(
    at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.send(
    at org.apache.synapse.endpoints.AbstractEndpoint.send(
    at org.apache.synapse.endpoints.AddressEndpoint.send(
    at org.apache.synapse.core.axis2.ProxyServiceMessageReceiver.receive(
    at org.apache.axis2.engine.AxisEngine.receive(
    at org.apache.synapse.transport.passthru.ServerWorker.processNonEntityEnclosingRESTHandler(
    at org.apache.axis2.transport.base.threads.NativeWorkerPool$
    at java.util.concurrent.ThreadPoolExecutor.runWorker(
    at java.util.concurrent.ThreadPoolExecutor$
    Caused by: java.lang.ClassNotFoundException: class org.apache.qpid.jndi.PropertiesFileInitialContextFactory not found
    at org.wso2.carbon.context.internal.CarbonContextDataHolder.classForName(
    at org.wso2.carbon.context.internal.CarbonContextDataHolder.access$800(
    at org.wso2.carbon.context.internal.CarbonContextDataHolder$CarbonInitialJNDIContextFactoryBuilder.createInitialContextFactory(
    … 24 more

    Please help me on this,


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s