6 Replies Latest reply on Feb 28, 2007 10:59 AM by RAJENDRA KAVURI

    Issues w/ JBoss Messging Cluster Environment when using Dura

    RAJENDRA KAVURI Newbie

      I am trying to set up the JBoss cluster in two machines. Here are the steps I have followed to set up and test the examples -

      1) Installed the JBoss4.0.5 on 2 machines by using the default partition name
      2) Modified the config files to refer to our in house Oracle Database
      3) Installed the jboss-messaging1.2.CR1 on both the machines
      4) Modified/added the config files to refer in house Oracle Database
      5) Started the servers
      6) Verified that the JMS related Tables have created in Oracle Database or not. They are created.
      6) Ran the examples on Node1 machine
      - When both Nodes are up and running
      - Queue and Topic examples ran well
      - Getting exceptions while trying to run the other(Queue Failover, mdb etc.) examples.
      - When I shut down the Node1 server
      - None of the examples are running
      7) Modifed jndi.properties file to set PORVIDER_URL parameter to 2 Nodes URLs on Node1 machine
      - When both Nodes are up and running
      - Queue and Topic examples ran well
      - Getting exceptions while trying to run the other(Queue Failover, mdb etc.) examples.
      - When I shut down the Node1 server
      - Queue and Topic examples ran well
      - Getting exceptions while trying to run the other(Queue Failover, mdb etc.) examples.

      After the above steps, I have following questions -

      1) Why is Auto-Failover is not working?
      2) Is there something wrong w/ my cluster configuration?
      3) Do the clients need to know about all the running clusters?
      4) How do both the clusters know each other?
      5) Is there any heartbeat mechanism b/w both the clusters?
      6) How do I make one of the cluster as ACTIVE node and the other as INACTIVE?(Inactive one becomes only active when the current active one becomes unavailable)


      Also I have written clients for both publisher and subscriber. We are planning to use durable subscriber. But I am unable to retrive any messages from my subscriber.

      Here is the code -


      
      Publisher
      
      import javax.jms.JMSException;
      import javax.jms.Message;
      import javax.jms.MessageListener;
      import javax.jms.Topic;
      import javax.jms.TopicConnection;
      import javax.jms.TopicConnectionFactory;
      import javax.jms.TopicPublisher;
      import javax.jms.TopicSubscriber;
      import javax.jms.TopicSession;
      import javax.jms.TextMessage;
      import javax.jms.DeliveryMode;
      import javax.naming.Context;
      import javax.naming.InitialContext;
      import javax.naming.NamingException;
      import java.util.Hashtable;
      import javax.jms.MessageListener;
      
      /** A JMS client example program that sends a TextMessage to a Topic*/
      
      public class TopicSendClient{
      
       TopicConnection conn = null;
       TopicConnection conn1 = null;
      
       TopicSession session = null;
      
       Topic topic = null;
      
       String CLIENT_ID = "TopicClient";
      
       long MESSAGE_LIFESPAN = 1800000; //30 minutes
      
       public void setupPubSub() {
       System.out.println("setupPubSub()");
      
      
       // Initial environment with various properties
       Hashtable<Object, Object> env = new Hashtable<Object, Object>();
       env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
       env.put(Context.PROVIDER_URL, "jnp://server1:1099,jnp://server2:1099");
       env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
      
       try{
       System.out.println("Before()");
       InitialContext iniCtx = new InitialContext(env);
      
       System.out.println("ConnectionFactory Not exists");
      
       //InitialContext iniCtx = new InitialContext();
       Object tmp = iniCtx.lookup("ConnectionFactory");
      
       System.out.println("ConnectionFactory exists");
      
       TopicConnectionFactory tcf = (TopicConnectionFactory) tmp;
      
       //topic = (Topic) iniCtx.lookup("topic/testDistributedTopic");
       topic = (Topic) iniCtx.lookup("topic/testTopic");
      
       System.out.println("TCF exists");
      
       conn = tcf.createTopicConnection();
       //conn1 = tcf.createTopicConnection();
      
       //conn.setClientID(CLIENT_ID);
      
       System.out.println("Topic testTopic exists");
      
       session = conn.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE);
      
       conn.start();
       }catch(Exception e){
       System.out.println("TopicConnection Not started"+e.getMessage());
       e.printStackTrace();
       }
      
      
       }
      
      
       public void sendAsync(String text) throws JMSException, NamingException {
      
       System.out.println("Begin sendAsync");
      
       // Setup the pub/sub connection, session
       setupPubSub();
      
       // Send a text msg
       TopicPublisher send = session.createPublisher(topic);
      
      
       TextMessage tm = session.createTextMessage(text);
      
       //send.publish(tm);
       send.publish( tm, DeliveryMode.PERSISTENT, Message.DEFAULT_PRIORITY, -1 );
      
       System.out.println("sendAsync, sent text="+ tm.getText());
      
       send.close();
      
       System.out.println("End sendAsync");
      
       }
      
      
       public void stop() throws JMSException {
      
       conn.stop();
      
       session.close();
      
       conn.close();
      
       }
      
      
       public static void main(String args[]) throws Exception {
      
       System.out.println("Begin TopicSendClient, now="+System.currentTimeMillis());
      
       TopicSendClient client = new TopicSendClient();
      
       client.sendAsync("A text msg, now="+System.currentTimeMillis());
      
       client.stop();
      
       System.out.println("End TopicSendClient");
      
       System.exit(0);
      
       }
      }
      
      Subscriber
      
      import javax.jms.JMSException;
      
      import javax.jms.Message;
      
      import javax.jms.MessageListener;
      
      import javax.jms.Topic;
      
      import javax.jms.TopicConnection;
      
      import javax.jms.TopicConnectionFactory;
      
      import javax.jms.TopicPublisher;
      
      import javax.jms.TopicSubscriber;
      
      import javax.jms.TopicSession;
      
      import javax.jms.TextMessage;
      
      import javax.naming.Context;
      
      import javax.naming.InitialContext;
      
      import javax.naming.NamingException;
      
      import java.util.Hashtable;
      
      /** A JMS client example program that synchronously receives a message a Topic */
      
      public class TopicRecvClient {
      
       TopicConnection conn = null;
      
       TopicSession session = null;
      
       Topic topic = null;
      
       String CLIENT_ID = "guest";
      
       long MESSAGE_LIFESPAN = 1800000; //30 minutes
       //long MESSAGE_LIFESPAN = 5000;
      
      
       public void setupPubSub() throws JMSException, NamingException{
      
       // Initial environment with various properties
       Hashtable<Object, Object> env = new Hashtable<Object, Object>();
       env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
       env.put(Context.PROVIDER_URL, "jnp://server1:1099,jnp://server2:1099");
       env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
       env.put (Context.SECURITY_PRINCIPAL, "guest");
       env.put (Context.SECURITY_CREDENTIALS, "guest");
       //env.put(Context.OBJECT_FACTORIES, "foo.bar.ObjFactory");
       //env.put("foo", "bar")
      
       InitialContext iniCtx = new InitialContext(env);
      
       Object tmp = iniCtx.lookup("ConnectionFactory");
      
       TopicConnectionFactory tcf = (TopicConnectionFactory) tmp;
      
       conn = tcf.createTopicConnection("guest","guest");
       //conn = tcf.createTopicConnection();
      
       topic = (Topic) iniCtx.lookup("topic/testTopic");
      
       //conn.setClientID(CLIENT_ID);
      
       session = conn.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE);
      
       conn.start();
      
       }
      
      
       public void recvSync() throws JMSException, NamingException
       {
      
       System.out.println("Begin recvSync");
      
       // Setup the pub/sub connection, session
      
       setupPubSub();
      
       // Wait upto 5 seconds for the message
      
       //TopicSubscriber recv = session.createSubscriber(topic);
      
       TopicSubscriber recv = session.createDurableSubscriber(topic, "SampleSubscription");
      
      
       Message msg = recv.receive(5000);
      
       if( msg == null )
      
       System.out.println("Timed out waiting for msg");
      
       else
      
       System.out.println("TopicSubscriber.recv, msgt="+msg);
      
       }
      
      
       public void stop() throws JMSException
       {
      
       conn.stop();
      
       session.close();
      
       conn.close();
      
       }
      
       public static void main(String args[]) throws Exception
       {
      
       System.out.println("Begin TopicRecvClient, now="+System.currentTimeMillis());
      
       TopicRecvClient client = new TopicRecvClient();
      
      
       client.recvSync();
       client.stop();
      
       System.out.println("End TopicRecvClient");
      
       System.exit(0);
      
       }
      }
      
      Thanks!!!
      Rajendra