Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

JMS supports two models for messaging as follows: 

...

Next, let's see a few real-life business use cases of the publisher-subscriber pattern. 

Table of Contents
maxLevel3
minLevel3

...

Scenario

...

overview

In this sample scenario, we create a JMS Topic in a broker server such as the WSO2 Message Broker (MB) and add a subscriber and a publisher as proxy services in WSO2 ESB. The diagram below depicts the sample scenario with WSO2 MB. 


...

Configuring the

...

broker server

Refer to section Configuring JMS Transport for details of setting up different broker servers for this sample.

...

Configuring WSO2 ESB as a

...

subscriber
Anchor
subscriber
subscriber

Follow the steps below to configure WSO2 ESB as a JMS Topic subscriber.
 
1. Download and install WSO2 ESB binary distribution using instructions in the Getting Started.
 
2. Open the <ESB_HOME>/repository/conf/JNDI.proerties properties file and point to the running broker server. This jndi property file has specifies the JNDI desecration designation of the topic that the proxy service will be subscribed to. A topic with the name SimpleStockQuoteService will be used in the scenario. For example,:

Code Block
# register some connection factories
# connectionfactory.[jndiname] = [ConnectionURL]
connectionfactory.QueueConnectionFactory = amqp://admin:admin@clientID/carbon?brokerlist='tcp://localhost:5673'
connectionfactory.TopicConnectionFactory = amqp://admin:admin@clientID/carbon?brokerlist='tcp://localhost:5673'
 
# register some queues in JNDI using the form
# queue.[jndiName] = [physicalName]
queue.MyQueue = example.MyQueue
 
# register some topics in JNDI using the form
# topic.[jndiName] = [physicalName]
topic.MyTopic = example.MyTopic
topic.SimpleStockQuoteService = SimpleStockQuoteService

4. Add following the proxy service to the synapse configuration of the ESB in order to configure it as a subscriber to the topic SimpleStockQuoteService.

To create proxy services, sequences, endpoints, message stores, processors etc. in ESB, you can either use the management console or copy the XML configuration to the source view. You can find the source view under menu Manage > Service Bus > Source View in the left navigation pane of the WSO2 ESB management console. You can add the proxy service to the ESB in the management console by choosing either by building proxy service in design view or copying the XML configuration in the source view. Alternatively, you can add a an XML file named SimpleStockQuoteService.xml to <ESB_HOME>/repository/deployment/server/synapse-configs/default/proxy-services.

A sample XML code segment that defines the proxy service is given below. 

Code Block
languagehtml/xml
<proxy xmlns="http://ws.apache.org/ns/synapse"
      name="SimpleStockQuoteService"
      transports="jms"
      startOnLoad="true"
      trace="disable">
  <description/>
  <target>
     <inSequence>
        <property name="OUT_ONLY" value="true"/>
        <log level="full"/>
        <drop/>
     </inSequence>
     <outSequence>
        <send/>
     </outSequence>
  </target>
  <parameter name="transport.jms.ContentType">
     <rules>
        <jmsProperty>contentType</jmsProperty>
        <default>application/xml</default>
     </rules>
  </parameter>
  <parameter name="transport.jms.ConnectionFactory">myTopicConnectionFactory</parameter>
  <parameter name="transport.jms.DestinationType">topic</parameter>
  <parameter name="transport.jms.Destination">SimpleStockQuoteService</parameter>
</proxy>

Whenever the topic SimpleStockQuoteService receives a message, it is delivered to this proxy service as well , since the proxy is subscribed to that topic. This proxy service simply logs the message and drops it.
 
5. Start the ESB by running,with one of the following commands:

  • <ESB_HOME>/bin/wso2server.sh (on Linux)
  • <MB_HOME>/bin/wso2server.bat (on Windows)

6. Note a A log message similar to the following getting will be printed on successful subscription.

...

Now you have a JMS topic in the broker server and a subscriber service in the ESB. To complete the scenario, you need to configure a topic publisher.

...

Configuring WSO2 ESB as a

...

publisher 

Follow the steps below to To create another proxy service as a topic publisher.

1. To create proxy services, sequences, endpoints, message stores, processors etc. in ESB, you can either use the management console or copy the XML configuration to the source view. You can find the source view under menu Manage > Service Bus > Source View in the left navigation pane of the WSO2 ESB management console.

Add the , add the following proxy service configuration to the synapse configuration of the ESB.

Code Block
languagehtml/xml
<proxy xmlns="http://ws.apache.org/ns/synapse" name="StockQuoteProxy" transports="http" statistics="disable" trace="disable" startOnLoad="true">
  <target>
     <inSequence>
        <property name="OUT_ONLY" value="true"/>
     </inSequence>
     <outSequence>
        <send/>
     </outSequence>
     <endpoint>
        <address uri="jms:/SimpleStockQuoteService?transport.jms.ConnectionFactoryJNDIName=TopicConnectionFactory&java.naming.factory.initial=org.wso2.andes.jndi.PropertiesFileInitialContextFactory&java.naming.provider.url=repository/conf/jndi.properties&transport.jms.DestinationType=topic"/>
     </endpoint>
  </target>
  <description></description>
</proxy>

 

Info
titleNote

Due to a bug in If you are using the source view in ESB 4.6.0 the management console, replace the '&' character of the above JMS endpoint url by URL with '&amp;'  

However, to use another instance of the ESB as the publisher, follow the instructions 2,3,4 in subscriber prior to adding the publisher proxy service configuration.

...

Invoking the publisher  

1. To invoke the publisher, simply use the StockQuoteClient service that comes with the ESB by default. Go to <ESB_HOME>/samples/axis2Client and run the following command.: 

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

This is how the The message flow happensis executed as follows:
 

  • When the stockquote client sends the message to the StockQuoteProxy service, the publisher will get invoked and send the message to the JMS topic.
  • The topic then delivers the message to all the subscribers of that topic. In this case, the subscriber is another ESB proxy service. 
Info
titleInfor
This sample uses only the ESB as the publisher and subscriber, although there can be many types of publishers and subscribers for a given JMS topic. The following article in the WSO2 library provides more information on different types of publishers and subscribers: http://wso2.org/library/articles/2011/12/wso2-esb-example-pubsub-soa.

...