Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

JMS supports two models for messaging as follows:  

...

There are many business use cases that can be implemented using the publisher-subscriber pattern. For example, consider a blog with subscribed readers. The blog author posts a blog entry, which the subscribers of that blog can view. In other words, the blog author publishes a message (the blog post content) and the list of subscribers (the blog readers) receive that message. Popular publisher/subscriber patterns like these can be implemented using JMS topics.Next, let's see a few real-life business use cases of the publisher-subscriber pattern. , as described in the following sections.

Table of Contents
maxLevel3
minLevel3

...

Scenario

...

overview

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

Image Removed

Configure the Broker Server

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

...

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 This example assumes you have already downloaded and installed WSO2 ESB (see Getting Started).

Image Added

Configuring the broker server

For this example, we will use ActiveMQ as our broker server. Follow the instructions in Configure with ActiveMQ to set up ActiveMQ for use with WSO2 ESB.

Configuring the publisher

  1. Open the <ESB_HOME>/repository/conf/JNDI.

...

  1. properties file and

...

  1. specify the JNDI

...

  1. designation of the topic

...

  1. (in this example, SimpleStockQuoteService). For example

...

  1. :

    Code Block

...

  1. # 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

...

  1. Next, add a proxy service named StockQuoteProxy and configure it to publish to the topic SimpleStockQuoteService.

...

  1. You can add the proxy service to the ESB using the management console, either by building the proxy service in the design view or by copying the XML configuration into the source view. Alternatively, you can add

...

  1. an XML file named

...

  1. StockQuoteProxy.xml to <ESB_HOME>/repository/deployment/server/synapse-configs/default/proxy-services.

...

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

...

  1. . Notice that the address URI specifies properties for configuring the JMS transport.

    Code Block
    languagehtml/xml

...

  1. <definitions xmlns="http://ws.apache.org/ns/synapse">
       <proxy name="StockQuoteProxy"
              transports="http"
              startOnLoad="true"
              trace="disable">
          <target>
             <endpoint>
    
                <address 
    uri="jms:/SimpleStockQuoteService?transport.jms.ConnectionFactoryJNDIName=TopicConnectionFactory&amp;java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&amp;java.naming.provider.url=tcp://localhost:61616&amp;transport.jms.DestinationType=topic"/>
             </endpoint>
             <inSequence>
                <property name="OUT_ONLY" value="true"/>
             </inSequence>
             <outSequence>
                <send/>
             </outSequence>
          </target>
       </proxy>
    </definitions>
    Info

    If you are using the source view in the management console, you must use '&amp;' instead of '&' in endpoint URLs, as shown in the example above. If you are saving this proxy service configuration as an XML file in the proxy-services directory, use '&' instead.

Configuring the subscribers

Next, you configure two proxy services that subscribe to the JMS topic SimpleStockQuoteService, so that whenever this topic receives a message, it is sent to these subscribing proxy services. Following is the sample configuration for these proxy services.

Code Block
languagehtml/xml
<definitions xmlns="http://ws.apache.org/ns/synapse">
    <proxy name="SimpleStockQuoteService1"
          transports="jms"
          startOnLoad="true"
          trace="disable">
      <description/>
      <target>
         <inSequence>
            <property name="OUT_ONLY" value="true"/>
            <log level="full"/>="custom">
               <property name="Subscriber1" value="I am Subscriber1"/>
            </log>
            <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,

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

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

Code Block
INFO
{org.wso2.andes.server.store.CassandraMessageStore}
-  Created Topic : SimpleStockQuoteService
INFO {org.wso2.andes.server.store.CassandraMessageStore} -  Registered Subscription tmp_127_0_0_1_44759_1 for Topic SimpleStockQuoteService

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

Configure WSO2 ESB as a Publisher 

Follow the steps below 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 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> <proxy name="SimpleStockQuoteService2"
          transports="jms"
          startOnLoad="true"
          trace="disable">
      <description/>
      <target>
         <inSequence>
            <property name="OUT_ONLY" value="true"/>
            <log level="custom">
               <property name="OUT_ONLYSubscriber2" value="trueI am Subscriber2"/>
            </log>
            <drop/>
         </inSequence>
         <outSequence>
            <send/>
         </outSequence>
     <endpoint> </target>
      <parameter <address uriname="jms:/SimpleStockQuoteService?transport.jms.ConnectionFactoryJNDIName=TopicConnectionFactory&java.naming.factory.initial=org.wso2.andes.jndi.PropertiesFileInitialContextFactory&java.naming.provider.url=repository/conf/jndi.properties&ContentType">
         <rules>
            <jmsProperty>contentType</jmsProperty>
            <default>application/xml</default>
         </rules>
      </parameter>
      <parameter name="transport.jms.ConnectionFactory">myTopicConnectionFactory</parameter>
      <parameter name="transport.jms.DestinationType=topic">topic</>parameter>
     </endpoint> <parameter  </target>name="transport.jms.Destination">SimpleStockQuoteService</parameter>
   <description><</description>proxy>
</proxy>

 

Info
titleNote

Due to a bug in the source view in ESB 4.6.0 management console, replace '&' character of the above JMS endpoint url by '&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.

Invoke the Publisher  

...

definitions>

Publishing to the topic

  1. Start the ESB with one of the following commands:

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

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

    A log message similar to the following will appear:

    Code Block
    INFO {org.wso2.andes.server.store.CassandraMessageStore} -  Created Topic : SimpleStockQuoteService
    INFO {org.wso2.andes.server.store.CassandraMessageStore} -  Registered Subscription tmp_127_0_0_1_44759_1 for Topic SimpleStockQuoteService
  2. To invoke the publisher, use the sample stockquote client service by navigating to <ESB_HOME>/samples/axis2Client and

...

  1. running the following command

...

  1. :

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

...

  1. The message flow

...

  1. is executed as follows:

    • When the stockquote client sends the message to the StockQuoteProxy service, the publisher

  • will get
    • is invoked and

  • send
    • sends the message to the JMS topic.

    • The topic
  • then
    • delivers the message to all the subscribers of that topic. In this case,
  • another
    • the subscribers are ESB proxy
  • service
    • services.
  •  
Info
titleInfor
This sample uses only the ESB as the publisher and subscriber, although there 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.