Results 1 to 7 of 7

Thread: Reconnecting JmsTemplate after JMS Server failure

  1. #1
    Join Date
    Nov 2004
    Posts
    10

    Default Reconnecting JmsTemplate after JMS Server failure

    All,
    I would like to use JmsTemplate to publish messages to a JMS server but I am not sure how the JmsTemplate will behave when the JMS server goes down for 5 minutes and then comes back up again.
    Do I need to restart the application to get the JmsTemplate to reconnect to the JMS Server?

    Thanks in advance,
    -Guillermo

  2. #2
    Join Date
    Aug 2004
    Location
    Linz, Austria
    Posts
    391

    Default

    The actual behavior depends on your JMS ConnectionFactory. JmsTemplate will fetch a Connection from the ConnectionFactory for each operation, putting the onus of Connection management onto the ConnectionFactory.

    In a J2EE environment, the ConnectionFactory will usually return transactional Connections, i.e. the same Connection for an entire transaction. As a further example (unrelated to your use case), you could define Spring's SingleConnectionFactory, holding a single JMS Connection and exposing it to all ConnectionFactory callers.

    In terms of reconnect behavior, concrete JMS providers will behave differently. If you're not happy with the raw behavior of your JMS provider / J2EE server, consider writing a ConnectionFactory proxy where you first check whether the Connection returned by the target ConnectionFactory is still valid, making sure to return an active Connection to the caller (i.e. JmsTemplate). This would be similar to how JDBC connection pools behave.

    Juergen

  3. #3
    Join Date
    Aug 2004
    Location
    London
    Posts
    164

    Default Re: Reconnecting JmsTemplate after JMS Server failure

    Quote Originally Posted by gt1601
    All,
    I would like to use JmsTemplate to publish messages to a JMS server but I am not sure how the JmsTemplate will behave when the JMS server goes down for 5 minutes and then comes back up again.
    Do I need to restart the application to get the JmsTemplate to reconnect to the JMS Server?
    -Guillermo
    If you use a decent JMS provider like ActiveMQ then you can enable auto-reconnection using the reliable: protocol. e.g. connect via the URL

    reliable:tcp://hostort

    and the JMS client will automatically reconnect for you under the covers without having to change your JMS code or fiddle with the JmsTemplate
    James Strachan
    ------------------
    Open Source Integration
    Iona

  4. #4
    Join Date
    Nov 2004
    Posts
    10

    Default

    Thanks for your response guys.

    I didn't know I could use the reliable protocol for only 1 server. What version of ActiveMQ do I need to do this?

    Is there an example of a Spring and ActiveMQ that uses the reliable protocol?.

    -Guillermo

  5. #5
    Join Date
    Aug 2004
    Location
    London
    Posts
    164

    Default

    Quote Originally Posted by gt1601
    Thanks for your response guys.

    I didn't know I could use the reliable protocol for only 1 server. What version of ActiveMQ do I need to do this?

    Is there an example of a Spring and ActiveMQ that uses the reliable protocol?.

    -Guillermo
    Reliable connections have been in ActiveMQ from around 2.0 I think (my memories a bit hazy, its been there for a long long time). Certainly if you use a recent version, like 3.1-M6 its all there working fine.

    The only requirement for the use of reliable protocol is prefixing your connection URL string with 'reliable:' on the JMS ConnectionFactory side of things, so any of the Spring / ActiveMQ examples should do the trick.

    e.g.

    <bean id="jmsFactory" class="org.activemq.ActiveMQConnectionFactory">
    <property name="brokerURL" value="reliable:tcp://localhost:61616"/>
    </bean>
    James Strachan
    ------------------
    Open Source Integration
    Iona

  6. #6
    Join Date
    Jan 2006
    Posts
    4

    Default JmsTemplate and JBoss clustering

    Hello,

    I have a web application here that uses Spring to send JMS messages to JBossMQ queues. Works fine.

    Now I set up JBoss clustering and "configured" Spring to use JBoss HA-JMS/HA-JNDI:

    java.naming.provider.url=node1:1100,node2:1100

    Another requirement for the JMS client to use clustering is that it must listen for server exceptions and reconnect. As far as I know, this is usually done by registering an ExceptionListener on the JMS Connection which will take care of reconnecting.

    I have done that with a litte test JMS client and failover to another node works fine.

    But how can I do this with Spring/JmsTemplate? I am completely new to Spring and I have no idea yet. Is it possible at all or should it be done with another approach (ConnectionFactory proxy as mentioned here)?

    Thanks in advance,
    Torsten

  7. #7
    Join Date
    Jun 2012
    Posts
    5

    Default JMS reconnect not happening m using a cachinconnectionfactory to connect to a MQ(IBM)

    Hi Juergen,

    m fairly new to spring and have two questions , please oblige me...

    1) in my scenario where m trying to connect to an MQ , when the QManager goes down , while the defaultmessagelistner container works fine like after the MQ QMGR is restarted it continues to recieve message by automatically reconnecting...while sending the same message fails coz the jmstemplate does'nt reconnect automatically. m using a cachingconnectionfactory for both container and jmstemplate , and the setreconnect is set to true. why does this happen??

    2)what will the connectionproxy look like if i have to write one for this problem? like wat do i do in the code?

    m in a big fix......highly appreciate any prompt help on this.....thanks in advance

    regards
    sunit

    Quote Originally Posted by Juergen Hoeller View Post
    The actual behavior depends on your JMS ConnectionFactory. JmsTemplate will fetch a Connection from the ConnectionFactory for each operation, putting the onus of Connection management onto the ConnectionFactory.

    In a J2EE environment, the ConnectionFactory will usually return transactional Connections, i.e. the same Connection for an entire transaction. As a further example (unrelated to your use case), you could define Spring's SingleConnectionFactory, holding a single JMS Connection and exposing it to all ConnectionFactory callers.

    In terms of reconnect behavior, concrete JMS providers will behave differently. If you're not happy with the raw behavior of your JMS provider / J2EE server, consider writing a ConnectionFactory proxy where you first check whether the Connection returned by the target ConnectionFactory is still valid, making sure to return an active Connection to the caller (i.e. JmsTemplate). This would be similar to how JDBC connection pools behave.

    Juergen

Similar Threads

  1. JmsTemplate and Acknowledge
    By mbarlotta in forum JMS
    Replies: 3
    Last Post: Nov 14th, 2005, 07:09 PM
  2. Replies: 6
    Last Post: Sep 29th, 2005, 04:25 AM
  3. Replies: 1
    Last Post: Aug 23rd, 2005, 09:24 AM
  4. Replies: 2
    Last Post: Dec 31st, 2004, 01:47 PM
  5. Replies: 15
    Last Post: Aug 28th, 2004, 08:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •