0

I am having a problem about JMS. The problem is, I have an application and it is trying to send a message through JMS , but after JMS server restart, it throws exception as when the server was down time. It is not reconnecting.

It is completely fine without a restart of JMS server and I am using weblogic 10.x.

Is it a problem about JMS configuration?

Thanks

Neron
  • 1,500
  • 7
  • 30
  • 52
  • Neron, try this solution: http://stackoverflow.com/questions/47683/reconnecting-jms-listener-to-jbossmq – dbf Jul 09 '12 at 07:33

1 Answers1

-1

Can you post your code how you are sending messages?

If you attempt to send a message when the JMS server is down, you will probably have an exception, and have to deal with that. When you attempt to send a message the next time, when the JMS server is restarted and running, you probably create a new connection from your connection factory. Reconnection will happend then:

// Let's say, you inject CF and Dest.
@Resource(lookup = "jms/ConnectionFactory")
private static ConnectionFactory cf;

@Resource(lookup = "jms/MyQueue")
private static Destination dest;

public void sendMessage(){ // called every time you need to send a message.
   try{
     Connection con = cf.createConnection(); // will reconnect, otherwise pooled.
     Session sess = con.createSession(false,Session.AUTO_ACKNOWLEDGE);
     MessageProducer prod = sess.createProducer(dest);
     Message msg = sess.createTextMessage("Hello, World");
     prod.send(msg);
     sess.close();
     con.close();
   }catch(Exception e){
     // handle errors 
   }
}

However, there are some built in failover/reconnecting features in Weblogic JMS, take a look at this page:

Oracle code listing and documentation about reconnecting JMS producers

Petter Nordlander
  • 22,053
  • 5
  • 50
  • 84
  • I have 4 jms servers and my application uses them as round robin sending. And in another machine, there is another 4 of them. So if my machine fails, it swithes another. In failure case, it will try all 8 jms servers to send messages. But the thing is, for ex, I am shutting down my first and it goews the second machine, then I open my first and close the second but it gives the exception even if it is open. So is there a way to know that, my server is ok at that time before sending it? – Neron Jul 09 '12 at 08:46
  • It's bad practice to create a new connection every time that you need to send a message. – Bryan Glazer Dec 30 '14 at 20:38
  • 1
    Well.. not really. closing connections and opening them again when you need to send another message is the only way you can deal with the problem stated here: reconnection at server restart. That is - unless you have the reconnection login in a catch statement but that is messy. The idea is to delegate the "reuse" part to the JEE app server or a pooling/caching connection factory. There are a few around, like Spring CachingConnectionFactory. Even spring JmsTemplate will create a new connection+session per message to cope with reconnection. – Petter Nordlander Dec 31 '14 at 00:26