This section explains, through an example scenario, how the Message Broker EIP can be implemented using WSO2 ESB. The following topics are covered:
Introduction to Message Broker
The Message Broker EIP decouples the destination of a message from the sender and maintains central control over the flow of messages. It receives messages from multiple destinations, determines the correct destination, and routes the message to the correct channel. The Message Broker EIP decouples messages from senders and receivers. For more information, refer to http://www.eaipatterns.com/MessageBroker.html.
Figure 1: Message Broker EIP
This example scenario demonstrates how WSO2 ESB works with WSO2 Message Broker to implement the Message Broker EIP. In this scenario, sent messages are put into a Message Broker queue, which any interested receiver can consume. If you want to add more receivers, you can use topics in WSO2 Message Broker in a similar manner discussed here.
Setting up WSO2 Message Broker
- Start Message Broker profile by executing the following script: <EI_HOME>/wso2/broker/bin/wso2server.sh
Setting up WSO2 ESB
- Download and install WSO2 ESB from http://wso2.com/products/enterprise-service-bus . Installation home will be referred to as
<ESB_HOME>. For a list of prerequisites and step-by-step installation instructions, refer to Installation Guide in the WSO2 ESB documentation.
- Copy the following files from
Enable the JMS transport receivers and senders by uncommenting the relevant sections in the
<ESB_HOME>/repository/conf/axis2/axis2.xmlfile. For example:
Define the following properties in the
Port should be 5675 for EI with MB profile. Default port is 5672 and MB profile runs with a port offset of 3.
You do not need Axis2 server for this example scenario. You do not view a response in StockQuote client.
ESB Console output:
INFO - LogMediator To: , WSAction: "urn:getQuote", SOAPAction: "urn:getQuote", MessageID: ID:8f192fb7-c90b-369e-b2af-4db9d38bc041, Direction: request, Subscriber = I am Subscribed to messages coming to StockQuoteProxy., 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:getQuote xmlns:m0="http://services.samples"><m0:request><m0:symbol>WSO2</m0:symbol></m0:request></m0:getQuote></soapenv:Body></soapenv:Envelope></soapenv:Body></soapenv:Envelope>
Start the ESB server and log into its management console UI (
//). In the management console,
navigate to the Main menu and click Source View in the Service Bus section . Next, copy and paste the following configuration, which helps you explore the example scenario, to the source view.
Simulating the sample scenario
Send a request using Stock Quote client to the proxy service in the following manner. For information on the Stock Quote client, refer to the Sample Clients section in WSO2 ESB documentation.
ant stockquote -Dtrpurl=http://localhost:8280/services/StockQuoteProxy -Dsymbol=WSO2
You will not view a response in
Note that the request is stored in WSO2 Message Broker. Any consumer can access the stored message by accessing
destinationMyQueue in WSO2 Message Broker.
How the implementation works
Let's investigate the elements of the ESB configuration in detail. The line numbers below are mapped with the ESB configuration shown above.
- Proxy service [line 3 in ESB config] - Defines a proxy service named
- endoint [line 10 in ESB config] - Defines an endpoint inside the proxy service. The address of the endpoint is a JMS URL. The JMS URL is made up of the following elements:
- jms:/myqueue - Looks for a JNDI entry
myqueue(see JNDI properties above).
- ? - Separator indicating extra attributes.
- transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory - Looks up
ConnectionFactoryin JNDI with name
- & - Separator (this will convert to ‘&’)
- java.naming.factory.initial=org.wso2.andes.jndi.PropertiesFileInitialContextFactory - Uses the andes properties-based JNDI.
- & - Another separator (this will convert to ‘&’)
- java.naming.provider.url=repository/conf/jndi.properties - Looks in
repository/conf/jndi.propertiesfor the JNDI properties file.