[jboss-user] [JBoss Messaging] - Re: New JBoss Messaging clustering

jbabad do-not-reply at jboss.com
Tue Dec 30 07:26:42 EST 2008


Hi, 

Thanks for the replies.
I realised that I forgot to mention that in the scenario when both sender and receiver programs are connecting to node1's JNDI and I then shut down the node, then the sender program crashes with the exception
Exception: Failed to route Reference[20162686882938884]:RELIABLE to testDistributedQueue
This is the same exception seen in the server log that I included initially.

I was hoping that the sender would transparently start sending the messages via the other node in the cluster. 
When the sender and receiver connect to the different nodes' JNDI, it does seem to cope with shutting down the node and the sender continues to send messages.

Sender code is as follows - basically a setup followed by a loop attempting to send 10 messages (some of the code not included):



  |     public void setUpJms(String port) throws Exception {
  | 
  |         String destinationName = System.getProperty("example.queue.name");
  | 
  | 
  | 
  |         ConnectionFactory cf = null;
  | 
  | //        try {
  |             // Create a connection to the clustered messaging instance
  | 
  |         Hashtable env = new Hashtable();
  |         env.put("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
  |         env.put("java.naming.provider.url","jnp://localhost:" + port);
  |         env.put("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
  |             ic = new InitialContext(env);
  | 
  |             cf = (ConnectionFactory) ic.lookup("/ClusteredConnectionFactory");
  | 
  |             Queue distributedQueue = (Queue) ic.lookup(destinationName);
  |             log("Distributed queue " + destinationName + " exists");
  | 
  |             // When connecting to a messaging cluster, the ConnectionFactory has the capability of
  |             // transparently creating physical connections to different cluster nodes, in a round
  |             // robin fashion ...
  | 
  |             connection = cf.createConnection();
  | 
  |             connection.start();
  | 
  |             // Send 2 messages to the queue
  | 
  |             session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
  | 
  |             messageProducer = session.createProducer(distributedQueue);
  | 
  |             displayProviderInfo(connection.getMetaData());
  | 
  |             return;
  | 

  |     public void sendMessage( String message) throws JMSException
  |     {
  | 
  |             TextMessage message1 = session.createTextMessage(message);
  | 
  |              messageProducer.send(message1);
  |         
  |     }
  | 

  |        public static void main(String[] args)
  |        {
  |            System.setProperty("example.queue.name", "/queue/testDistributedQueue");
  | 
  |            
  |            try {
  |                JmsSender sender  = new JmsSender();
  |                sender.setUpJms(args[0]);
  | 
  |                for (int i=0; i<10; i++)
  |                {
  |                    log("Sending message: " + i);
  |                    sender.sendMessage("Hello" + i);
  |                    Thread.sleep(5000);
  |                }
  |                sender.close();
  |            } catch (Exception e) {
  |                log("Exception: "  + e.getMessage());
  |            }
  |        }
  | 

I then realised that I wasn't trapping the exception in the sendMessage method which meant that it filtered up to main and exited the program.

Obvious really, but still strange as this wasn't an issue when the sender and receiver programs were connecting to different nodes?

Trapping the exception in sendMessage meant that I could attempt to re-send the message.  Going down this route I saw a couple of things.

Doing a CTRL-C shutdown I still saw messages either going missing or being duplicated. I  still sometimes got the "Failed to Route" error, but at least I could continue to attempt to send messages.
Killing the JBoss instance (kill -9) seemed to fail-over OK with no loss of data

So, 

 are these observations consistent with what would be expected?
(Note in both these scenarios both  the sender and receiver initially connect to the same node)
Why the difference when both programs are initially connected to a single node - when I need to trap the send exception - as opposed to when they are connected to different nodes and that exception doesn't appear to happen?


Cheers,
Joseph.

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4198912#4198912

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4198912



More information about the jboss-user mailing list