Announcement Announcement Module
Collapse
No announcement yet.
Does the spring JNDI also support failover? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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:

    Code:
    jndi.provider.url=jnp://localhost:1099,jnp://localhost:2099
    jndi.factory.init=org.jnp.interfaces.NamingContextFactory
    jndi.factory.pkgs=org.jboss.naming:org.jnp.interfaces
    And the spring configuration is as follows:
    Code:
        <bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
            <property name="environment">
                <props>
                    <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>
                </props>
            </property>
        </bean>
    
        <bean id="connectionFactoryInit" class="org.springframework.jndi.JndiObjectFactoryBean">
            <property name="jndiTemplate" ref ="jndiTemplate"/>
            <property name="jndiName" value="ConnectionFactory"/>
        </bean>
        
        <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>
       
        <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>
    	</bean>
    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
    Code:
    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(HornetQConnection.java:593)
    	at org.hornetq.jms.client.HornetQConnection.createSession(HornetQConnection.java:159)
    	at org.springframework.jms.connection.SingleConnectionFactory.createSession(SingleConnectionFactory.java:406)
    	at org.springframework.jms.connection.CachingConnectionFactory.getSession(CachingConnectionFactory.java:225)
    	at org.springframework.jms.connection.SingleConnectionFactory$SharedConnectionInvocationHandler.invoke(SingleConnectionFactory.java:534)
    	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
    HornetQJMSConnectionFactory
    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, 10:55 PM.

    Comment


    • #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.

      Comment


      • #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.

        Comment

        Working...
        X