Announcement Announcement Module
No announcement yet.
Does the spring JNDI also support failover? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Does the spring JNDI also support failover?

    Hi ,
    I am using HornetQ as our message broker and create connection over JNDI, my jndi props look like the following:

    And the spring configuration is as follows:
        <bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
            <property name="environment">
                    <prop key="java.naming.provider.url">${jndi.provider.url}</prop>
                    <prop key="java.naming.factory.initial">${jndi.factory.init}</prop>
                    <prop key="java.naming.factory.url.pkgs">${jndi.factory.pkgs}</prop>
        <bean id="connectionFactoryInit" class="org.springframework.jndi.JndiObjectFactoryBean">
            <property name="jndiTemplate" ref ="jndiTemplate"/>
            <property name="jndiName" value="ConnectionFactory"/>
        <bean id="userConnectionFactory" class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter">
      	    <property name="targetConnectionFactory"><ref bean="connectionFactoryInit"/></property>
            <property name="username" value="${jms.user}"></property>
            <property name="password" value="${jms.pass}"></property>
        <bean id="connectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
    		<property name="targetConnectionFactory" ref="userConnectionFactory"></property>
    		<property name="sessionCacheSize" value="10"></property>
    		<property name="reconnectOnException" value="true"></property>
    I have configured the hornetq servers for failover with one as a passive backup which automatically comes up when the active one fails. What I see is that when the live server goes down, the backup server becomes the live one. However on the client side all the connections fail and are not failed over to the new live server. Any help appreciated.

    Error log as
    012-12-14 14:49:26,922 [redelivery-scheduler1-thread-1] ERROR [com.clairmail.event.impl.EventMessageDispatcherImpl] SEVERE unable to process event-message to topic
    javax.jms.IllegalStateException: Connection is closed
    	at org.hornetq.jms.client.HornetQConnection.checkClosed(
    	at org.hornetq.jms.client.HornetQConnection.createSession(
    	at org.springframework.jms.connection.SingleConnectionFactory.createSession(
    	at org.springframework.jms.connection.CachingConnectionFactory.getSession(
    	at org.springframework.jms.connection.SingleConnectionFactory$SharedConnectionInvocationHandler.invoke(
    	at $Proxy48.createSession(Unknown Source)

  • #2
    I would strongly recommend reading the javadocs as well before taking on spring. You see, you're creating a connection factory via
    org.springframework.jms.connection.CachingConnecti onFactory
    which in turn is child of
    org.springframework.jms.connection.SingleConnectio nFactory
    . The javadocs of this class say
    A JMS ConnectionFactory adapter that returns the same Connection from all createConnection() calls, and ignores calls to Connection.close().
    I don't think you can use this connection factory implementation, but some other implementation like
    and that also means, some of the JARs from HornetQ have to be referenced in your project

    You can take a look at Stack-Overflow or Here
    Last edited by objectamit; Dec 14th, 2012, 09:55 PM.


    • #3
      Thank you objectamit! I did some more debugging and reading through the hornetq docs. Actually the connection resetting should be transparent to the client and hence should have automatically failed over. However in most hornetq forum posts, I see people blaming the spring classes for faults and hence thought of posting here as well as on the hornetq forum. I tried a simple client without using spring and it failed, so I guess now I should be waiting for a reply on the hornetq forum. Thank you for taking time to reply.


      • #4
        Did you also happen to go through the links that I provided. Cause if you have, I don't see any reason why your configuration is not successful? Please go through it once before you feel stuck again.

        People will keep blaming. Nobody can stop them but if we concentrate on problem and try to resolve it and then look at the solution, one should know for sure that here or in cases like these, SPRING just acts as a mirror. You see in it what you bring in front of it.