Version 21

    WARNING: This is an example supplied by a user. Creating a durable subscription without specifying the client id is bad. TODO: Fix this example

     

    How to configure MDBs to subscribe to a topic in a cluster?

     

    Asynchronous messaging is useful for invalidation purpose across a cluster.

     

     

    Let's imagine a possible scenario composed of 2 nodes running in a cluster.

     

     

    • hajms runs the JMS server in HA-Singleton mode. This server hosts the topic.

    • node1 runs an MDB with durable subscription on the topic

    • the JMS client publishes messages to the topic

     

        node1             hajms
         MDB  <---------  topic
                            ^
                            |
                            |
                        JMS client   
    

     

    Each node receives a copy of the message. This "notification" may then be use to trigger cached data invalidation or a configuration reload.

     

     

    Setup the environment

     

    Installation

     

     

    Create a home directory. For now on we'll call it {wiki.dir}

     

    Download and unpack JBossAS 4.0.1SP1 in {wiki.dir}

     

    Get the attached package hajms-clusteredtopic.zip and explode it into {wiki.dir}

     
       /{wiki.dir}
         /hajms-clusteredtopic
         /jboss-4.0.1sp1
    

    Create three copies of the all server configuration as follows

       /jboss-4.0.1sp1
         /server/hajms
         /server/node1
    

        

       To make this demo more fun, we will bind each instance to a separate ip address. So first step is to configure those ips.

        

    Here is what I've got on my box

        hajms     --> 192.168.4.150  
        node1     --> 192.168.4.151
    

          

      Configuration

       

        N/A

       

                         

    Deploying the mdb

     

    On node1, the mdb makes a durable subscription anonymously to the topic bound in HA-JNDI as topic/testDurableTopic.

     

     ejb-jar.xml
     
       ...
       <enterprise-beans>
          <message-driven>
             <ejb-name>DurableTopicBean</ejb-name>
             <ejb-class>jmslab.mdb.DurableTopicBean</ejb-class>
             <transaction-type>Container</transaction-type>
             <message-driven-destination>
                <destination-type>javax.jms.Topic</destination-type>
             </message-driven-destination>
             <subscription-durability>Durable</subscription-durability>
          </message-driven>
       </enterprise-beans>
       ...
    

        

        

     jboss.xml
     
       ...
       <enterprise-beans>
          <message-driven>
             <ejb-name>DurableTopicBean</ejb-name>
             <destination-jndi-name>topic/testDurableTopic</destination-jndi-name>
             <configuration-name>Standard Message Driven Bean</configuration-name>
          </message-driven>
       </enterprise-beans>
       
       ...                 
    

                         

      Let's deploy the mdb on both nodes

       

        cd to /hajms-clusteredtopic/src/build and type

      
        $ant deploy
    

                         

        A deployment called MDB.jar is created and copied over to each node (/deploy directory)

         

         

    Starting the cluster

     

    Open 2 separate command line windows and start both node1 and hajms

     
       $sh run.sh -c hajms -b 192.168.4.150
       
       $sh run.sh -c node1 -b 192.168.4.151
    

        

       

       

    Running the client

     

    It's time to publish some messages to the topic

     

     

     

    Open another command line window and cd to /hajms-clusteredtopic/src/build  

     
     $ant run-failover
    

       

     

    On each instance, you should see the messages behing processed

     

     

       16:53:50,312 INFO  [DurableTopicBean] received message ID:7-11169464302961, payload: 0
       16:53:51,312 INFO  [DurableTopicBean] received message ID:7-11169464313122, payload: 1
       16:53:52,312 INFO  [DurableTopicBean] received message ID:7-11169464323123, payload: 2
       16:53:53,312 INFO  [DurableTopicBean] received message ID:7-11169464333124, payload: 3
       16:53:54,312 INFO  [DurableTopicBean] received message ID:7-11169464343125, payload: 4
    

     

     

     

    Explanations

     

    coming soon...

     

     

     

     

    NOTE:

     

    1. This procedure can not be used as-is with JBossAS 4.0.2. Because of a bug in HA-JNDI auto-discovery, the client is not able to look up the topic.

       Until this issue is fixed, you should use the following JNDI properties

       java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
       #java.naming.provider.url=192.168.4.150:1100     <--- comment out this line and update it accordingly
       java.naming.factory.url.pkgs=org.jboss.naming
    

     

    Second_file:

    The second attached file hajms-clusteredtopic.tar.bz2 includes a SLSB with a method postMessage(int i).  This is included to demonstrate that you can post messages from within a cluster. The file also includes a SLSB client that can be run using ant

     
     $ant run-slsbclient
    

     

    The original jms client ant target has been changed from run-failover to

     
     $ant run-mdbclient
    

       

    This file also brings the MDB config up to J2EE 1.4.