Author |
Message
|
eugen |
Posted: Wed Mar 30, 2011 12:18 am Post subject: ActiveMQ and JMSInput |
|
|
Novice
Joined: 28 Dec 2010 Posts: 22
|
Hello,
Either this has been discussed here on mqseries and I am blind or I am missing something.
So what I want to achieve is pretty darn simple, use activemq as a JMS Provider and consume messages from it using a JMSInput node. Seems easy right? Well, using pure Java coding this is indeed very easy, took me like 10 minutes to do it. Using the broker, well..
So, the activemq does not have a full JNDI server, meaning that when you create the "InitialContext" (java-speaking) you have to pass in the properties file with the values, something like this:
java.naming.factory.initial = org.apache.activemq.jndi.ActiveMQInitialContextFactory
# use the following property to configure the default connector
java.naming.provider.url = tcp://localhost:61616
# use the following property to specify the JNDI name the connection factory
# should appear as.
connectionFactoryNames = connectionFactory
# register some queues in JNDI using the form
# queue.[jndiName] = [physicalName]
queue.MyQueue = TESTQUEUE
Now if I move to JMSInput node, things become a bit unclear (at least for me). This is what I am trying to do:
Basic Tab --> Source Queue: TESTQUEUE
JMS Connection Tab --> JMS Provider Name : ActiveMQ
JMS Connection Tab --> Initial Context Factory : org.apache.activemq.jndi.ActiveMQInitialContextFactory
JMS Connection Tab --> Location JNDI Bindings : /home/mqbrkr/jndi.properties
JMS Connection Tab --> Connection Factory Name : queueConnectionFactory
This is obvious wrong. The JMSInput Node is expecting a JNDI-Directory of where the JNDI names are and not the file. But how can I specify one if the activemq does not provide one? Should I use the mqsisetdbparams may be? And if yes then how do I do that? I have tried some things, but none seem to work - I get various errors on various (obviously wrong) setting.
Could anyone may be give me a hint of what is going on?
Cheers,
Eugene.
Then |
|
Back to top |
|
 |
mqjeff |
Posted: Wed Mar 30, 2011 2:00 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
To the best of my knowledge, without having actually checked because I'm just not awake enough yet this morning, there are two things.
First, there should be documentation available either in a developerWorks article or in the v7 information center about how to configure a JMSProvider for ActiveMQ.
Secondly, there is a thread within the last month or so in which I have provided some discussion on specifically configuring a JMSProvider with ActiveMQ, and I believe there was a successful resolutoin.
But again, I've not looked, so I don't have any links handy. |
|
Back to top |
|
 |
fjb_saper |
Posted: Wed Mar 30, 2011 2:09 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Eugen,
You need to look at 2 sides of the same coin. It looks to me that you are looking at the JNDI setup from the side of the ActiveMQ server.
What you need to do is look at the JNDI setup from the side of the ActiveMQ client. This has yet nothing to do with WMB and is still in the pure Java realm.
So as a Java client, what is your JNDI provider? What is the provider class? What is the initial context URL. Without loading any properties, can you do a lookup of the queues? :
The following setup should be sufficient.
Code: |
java.naming.factory.initial = org.apache.activemq.jndi.ActiveMQInitialContextFactory
java.naming.provider.url = tcp://some_ActiveMQ_server:61616 |
First do the ActiveMQ server setup. Define the JMS ConnectionFactory name, define the Destination names.
On a different box do the ActiveMQ client setup and reference the server in the url. Then try to lookup the information the server has in the JNDI.
The client setup is the information you will need for the WMB setup.
Have fun  _________________ MQ & Broker admin |
|
Back to top |
|
 |
mqjeff |
Posted: Wed Mar 30, 2011 2:44 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
FJ - ActiveMQ doesn't make as much distinction on these lines as other JMS providers. |
|
Back to top |
|
 |
fjb_saper |
Posted: Wed Mar 30, 2011 3:25 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Well I am sure this will be of interest:
http://activemq.apache.org/jndi-support.html
However I fault the documentation for not clearly defining the place where the corresponding properties file needs to be set. (class loader hell?)
Apparently all it requires is for a jndi.properties file to be on the classpath... So for the broker make sure all the jar dependencies are there (hello Spring??) and that you have the jndi.properties on the classpath.
And I am disappointed that the JNDI server mascarades as network ready type of JNDI server (tcp:) when it is really file based...  _________________ MQ & Broker admin |
|
Back to top |
|
 |
mqjeff |
Posted: Wed Mar 30, 2011 4:10 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Yes. I remember reviewing that page the last time I was providing assistance with ActiveMQ in Broker.
But I'm starting to doubt my morning brain's assumption that I provided that assistance here.
Eugene - You should put the properties file into a .jar file and then put that in either shared-classes or the location you've configured on the JMSProvider configurable service. It needs to be in a jar file because the named class loaders in broker only load .jar files from directories, not all files in a given directory. |
|
Back to top |
|
 |
eugen |
Posted: Wed Mar 30, 2011 4:43 am Post subject: |
|
|
Novice
Joined: 28 Dec 2010 Posts: 22
|
Hey, thank you for the answers. This is really nice from you..
@mqjeff - ok so I did place the jar file that contains the jndi.properties in the shared-classes folder, then restarted the broker.
Here is the file I used:
java.naming.provider.url = tcp://192.168.5.167:61616
connectionFactoryNames = connectionFactory, queueConnectionFactory, topicConnectionFactry
queue.MyQueue = TESTQUEUE
On the JMSInput Node:
Basic Tab --> Source Queue: MyQueue
JMS Connection Tab --> JMS Provider Name : ActiveMQ
JMS Connection Tab --> Initial Context Factory : org.apache.activemq.jndi.ActiveMQInitialContextFactory
JMS Connection Tab --> Location JNDI Bindings : tcp://192.168.5.167:61616
JMS Connection Tab --> Connection Factory Name : connectionFactory
And.. it's working!
You guys are awesome! (as usual)
Cheers,
Eugene.
Last edited by eugen on Wed Mar 30, 2011 5:03 am; edited 1 time in total |
|
Back to top |
|
 |
mqjeff |
Posted: Wed Mar 30, 2011 5:01 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
No, the location Jndi Bindings is not the properties file... it's the url as mentioned in the link provided by FJ.
I'm going to have to dig through some things to find the information I'd discovered last time. |
|
Back to top |
|
 |
karthick.sraman |
Posted: Fri Apr 01, 2011 11:04 am Post subject: Active MQ and JMS Input/Output |
|
|
Newbie
Joined: 01 Apr 2011 Posts: 4
|
Hi,
I am trying to set up a JMS Output Node to send a message to Active MQ and did the same thing that Eugene has mentioned. But it is still not working and when I run the message flow, I get the following exception.
[Test Client Error]javax.naming.NoInitialContextException: Failed to create InitialContext using factory specified in hashtable {java.naming.provider.url=tcp://localhost:61616, java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory} [Root exception is java.lang.NullPointerException]
[Test Client Error]JMS output monitor encountered an error when attempting to get message:
[Test Client Error]java.lang.NullPointerException
Here are the steps that I did.
1. Set up a configurable Service for ActiveMQ in Message Broker Explorer and the details are below.
initialContextFactory org.apache.activemq.jndi.ActiveMQInitialContextFactory
jarsURL
C:\activeMQ_Jars
jndiBindingsLocation
tcp://localhost:61616
and then here are the properties for my JMSOutput Node in WMB Toolkit
JMSProviderName - ActiveMQ
Initial Context Factory - org.apache.activemq.jndi.ActiveMQInitialContextFactory
Location JNDI bindings - tcp://localhost:61616
Connection Factory Name - jms/BRESQueueConnectionFactory
Also in the jarsURL path I have a jar called "jndi_properties.jar" which has the jndi.properties file inside it and the contents of it are as follows:
java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory
java.naming.provider.url=tcp://localhost:61616
connectionFactoryNames=jms/BRESQueueConnectionFactory
queue.BRESQueueIn=BRESQueueIn
All the other needed jars files are in the C:\activeMQ_Jars folder.
With all these set up done and when I run the flow, I get the exception as given above. Can you please help in thie regard.
Thanks,
Karthick. |
|
Back to top |
|
 |
eugen |
Posted: Sun Apr 03, 2011 10:33 pm Post subject: |
|
|
Novice
Joined: 28 Dec 2010 Posts: 22
|
Hey Karthick,
You can give up on the jar files in the shared-classes folder actually.
This is what I recommend :
1. Try to build a Java Client for the ActiveMQ and see if that works.
See if you can build a JMS Producer and a JMS Consumer.
This should give you a hint of where your problem is.
2. Probably obvious but the problem is because of this :
jms/BRESQueueConnectionFactory
Have you created this Connection Factory on the ActiveMQ? Are you sure it exists? If you are using the default installation without doing anuthing special, then the answer is no, it does not exist. If you want to use it, be sure to create it.
Also try to replace it with:
"connectionFactory" see if it works.
Cheers,
Eugene. |
|
Back to top |
|
 |
fjb_saper |
Posted: Mon Apr 04, 2011 4:15 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
@Karthic
I noticed that you prefixed your names with jms. In my experience file based contexts don't like this. So try first as eugen suggested to attach in a standalone jms program. If that does not work, try again without prefixing your jndi names with "jms/", and let us know what worked.  _________________ MQ & Broker admin |
|
Back to top |
|
 |
karthick.sraman |
Posted: Mon Apr 04, 2011 7:44 am Post subject: JMS Input/Output node |
|
|
Newbie
Joined: 01 Apr 2011 Posts: 4
|
Hi Eugene/MQ Broker Admin,
I have actually created the BRESConnectionFactory and the associated queue for the connection factory in the WASCE admin console.
Also, I am having a small web app (a servlet) which puts the message on to this queue. It is working fine from the web application.
But when it comes to the Message Broker Input node, it does not work. It is not able to create an instance of the InitialContextFactory. Please see the error below.
"Failed to create InitialContext using factory specified in hashtable {java.naming.provider.url=tcp://localhost:61616, java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory} [Root exception is java.lang.NullPointerException]"
I also tried the connectionFactory name without the jms prefix. Still no luck. In WASCE console, it shows the name of the connection factory as jms/BRESQueueConnectionFactory. Thats why I gave the name like that in the JMS Output Node.
Please let me know an update on this issue.
Thanks,
Karthick. |
|
Back to top |
|
 |
karthick.sraman |
Posted: Mon Apr 04, 2011 12:23 pm Post subject: JMS Output |
|
|
Newbie
Joined: 01 Apr 2011 Posts: 4
|
Hi,
I figured out one thing from my Java Standalone program that if the supporting jar files are not presnet in the Classpath, I get the same exception from the Java application also as that of the exception from the WMB Flow.
I have all the needed jar files in place for the message flow. But still I think something is not correct.
Any help in this regard is appreciated.
Thanks,
Karthick. |
|
Back to top |
|
 |
eugen |
Posted: Mon Apr 04, 2011 10:13 pm Post subject: |
|
|
Novice
Joined: 28 Dec 2010 Posts: 22
|
Hey,
When you say "I have all the needed jar files in place for the message flow" where do you mean are they? Also did you restart the broker?
I will give a shot myself to re-produce, but can you please tell the exact steps you are making?
Thank You,
Eugene. |
|
Back to top |
|
 |
eugen |
Posted: Mon Apr 04, 2011 11:34 pm Post subject: |
|
|
Novice
Joined: 28 Dec 2010 Posts: 22
|
WASCE? I am really confused right now - first you said about ActiveMQ and now WASCE?
Can you be a bit more precise on what exactly are you trying to achieve and what are you using?
Cheers,
Eugene. |
|
Back to top |
|
 |
|