Versions Compared

Key

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

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

Anchor
subscriber
subscriber

Configuring WSO2 ESB as a

...

subscriber

Follow the these steps below to configure WSO2 ESB as a JMS Topic topic subscriber.
 1.

  1. Download and install WSO2 ESB binary distribution using instructions in the Getting Started. 
  2.  

...

  1. Open the <ESB_HOME>/repository/conf/JNDI.properties file and point to the running broker server. This file specifies the JNDI 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

     

...

  1. Add the proxy service to the ESB to configure it as a subscriber to the topic SimpleStockQuoteService. 

    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 an XML file named SimpleStockQuoteService.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. 

    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, since the proxy is subscribed to that topic. This proxy service simply logs the message and drops it.

...

  1.  

...

  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 be printed on successful subscription.

...

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

If you are using the source view in the management console, replace the '&' character of the above JMS endpoint URL with '&amp;'  

Invoking the publisher  

...