Trying out XA, part 6: jndi.properties rabbit trail
Posted by danielmeyer on July 9, 2008
In part 5, we were thinking the problem might be having the wrong class specified in the resource adapter configuration file.
So, based on the ActiveMQ JNDI Support page, looks like we need to put a jndi.properties file with our project…
Tried that and my new queue connection factory doesn’t show up in JNDIView in the JBoss JMX console. Hmm. Moved jndi.properties into the same package as my java classes to see if JBoss would see it there… same result.
Hey, jndi.properties exists in JBoss’s conf directory (in my case, server/default/conf/jndi.properties). How ’bout I first try adding the settings there and bouncing JBoss, and see if the entries show up in the JMX console. Then I can do it a better way once it’s working, huh?
I’m adding these settings to jndi.properties:
java.naming.provider.url = tcp://localhost:61616
connectionFactoryNames = DapperQueueConnectionFactory
queue.DapperQueue = XATry.DapperQueue
JBoss doesn’t seem to immediately notice the change (no output on the console anyway) so let’s bounce JBoss…
Boom!
javax.naming.CommunicationException: Could not obtain connection to any of these urls: tcp://localhost:61616 and discovery failed with error: javax.naming.CommunicationException: Receive timed out [Root exception is java.net.SocketTimeoutException: Receive timed out] [Root exception is javax.naming.CommunicationException: Failed to connect to server tcp:1099 [Root exception is javax.naming.ServiceUnavailableException: Failed to connect to server tcp:1099 [Root exception is java.net.UnknownHostException: tcp: tcp]]]
Maybe I should have ActiveMQ running at the time I start JBoss…
Hmm, same error even with ActiveMQ running.
You know, at the top of JBoss’s jndi.properties file there is this comment:
# DO NOT EDIT THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING
I guess they were right! :)
I removed the things I had added to the jndi.properties file, and JBoss starts clean again.
Properties in the Spring beans?
I seem to remember <properties> entries you can put within your Spring bean definitions. Perhaps I should put the settings there instead of in jndi.properties. Let’s see…ah yes, it was in the Spring manual Appendix A, the part about the jee:jndi-lookup tag.
So instead of
<jee:jndi-lookup id="connectionFactory" jndi-name="java:activemq/ConnectionFactory" />
let’s try this:
<jee:jndi-lookup id="connectionFactory" jndi-name="DapperQueueConnectionFactory">
<jee:environment>
java.naming.provider.url=tcp://localhost:61616
connectionFactoryNames=DapperQueueConnectionFactory
queue.DapperQueue=XATry.DapperQueue
</jee:environment>
</jee:jndi-lookup>
Deploying this blows up because again I don’t have ActiveMQ running at port 61616. Let’s start up ActiveMQ and try again…
Hmm, no new messages in the console, but I think I read somewhere that ActiveMQ doesn’t read the jndi.properties file until the queue (or whatever) is actually going to be used. So let’s try enabling the DefaultMessageListenerContainer, pointing to the beans which have been revised this way:
<bean id="messageListener" class="com.example.service.QueueConsumer" /> <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager" /> <jee:jndi-lookup id="connectionFactory" jndi-name="DapperQueueConnectionFactory"> <jee:environment> java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory java.naming.provider.url=tcp://localhost:61616 connectionFactoryNames=DapperQueueConnectionFactory queue.DapperQueue=XATry.DapperQueue </jee:environment> </jee:jndi-lookup> <jee:jndi-lookup id="dapperQueue" jndi-name="DapperQueue"> <jee:environment> java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory java.naming.provider.url=tcp://localhost:61616 connectionFactoryNames=DapperQueueConnectionFactory queue.DapperQueue=XATry.DapperQueue </jee:environment> </jee:jndi-lookup> <bean id="jmsContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer"> <property name="messageListener" ref="messageListener" /> <property name="transactionManager" ref="transactionManager" /> <property name="connectionFactory" ref="connectionFactory" /> <property name="destination" ref="dapperQueue" /> </bean>
Result:
13:59:51,947 ERROR [ContextLoader] Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘connectionFactory’: Invocation of init method failed; nested exception is javax.naming.NamingException: Invalid broker URL
Guess we still don’t have it!
Update: See the Something Works! post for the stunning near-conclusion of the example…
farheen said
Hi,
I too am facing the same issue. I am using JBoss 4.0.3 and ActiveMQ 5.4.3 version. But im not using
spring in my application. I tried the solution that u suggessted above but in vain. I am still
getting the error: Can you suggest what else I am missing. My JBoss server log states that ActiveMQ has started successfully.
18:11:16,579 DEBUG (Thread-3) [NamingContext] Failed to connect to vm:1099
javax.naming.CommunicationException: Failed to connect to server vm:1099 [Root exception is javax.naming.ServiceUnavailableException: Failed to connect to server vm:1099 [Root exception is java.net.ConnectException: Connection timed out: connect]]
at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:254)
at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1370)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:579)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:572)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at com.ingenix.icp.jms.JMSBridge.jndiLookup(JMSBridge.java:265)
at com.ingenix.icp.jms.JMSBridge.getConnection(JMSBridge.java:346)
at com.ingenix.icp.jms.JMSBridge.createSession(JMSBridge.java:305)
at com.ingenix.icp.jms.JMSListener.connect(JMSListener.java:70)
at com.ingenix.icp.jms.JMSMonitor.run(JMSMonitor.java:38)
at java.lang.Thread.run(Thread.java:619)
Caused by: javax.naming.ServiceUnavailableException: Failed to connect to server vm:1099 [Root exception is java.net.ConnectException: Connection timed out: connect]
at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:228)
… 10 more
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:519)
at java.net.Socket.connect(Socket.java:469)
at java.net.Socket.(Socket.java:366)
at java.net.Socket.(Socket.java:267)
at org.jnp.interfaces.TimedSocketFactory.createSocket(TimedSocketFactory.java:69)
at org.jnp.interfaces.TimedSocketFactory.createSocket(TimedSocketFactory.java:62)
at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:224)
… 10 more
danielmeyer said
Hi Farheen,
I’m sorry, I do not have the system I wrote about here available to me at the moment and am not able to research it right now… but have you read the next post in the series ( http://ourcraft.wordpress.com/2008/07/17/something-works/ ) ? I did get something working in that post, it turned out I had duplicate dependencies.
Hope this helps,
Daniel
farheen said
Hi Daniel,
Thank you for responding.
I could fix the issue by creating connection of type ActiveMQConnectionFactory in my client and passing the broker url as a paramter to the ActiveMQConnectionFactory constructor. But what I dont understand is that why is ActiveMQ unable to lookup the JNDI created by JBoss. I had earlier implemented HornetQ with JBoss and in that I did come across this issue.
Do you have any idea why is problem is occurring in ActiveMQ.
Thanks
Farheen