Yup, referencing ActiveMQ objects from your code nails your application to
ActiveMQ and makes it non-portable. It defeats the purpose of using the JMS.
If you're running an external (standalone) client, Spring would be a good
way to go, but if you want to still use the JNDI, then simply create a
jndi.properties file and put it in your CLASSPATH. You can then get the
initial context and a particular factory as follows.
Context ctx = new InitialContext();
ConnectionFactory factory = (javax.jms.ConnectionFactory)
ctx.lookup("localConnectionFactory");
You could also reference some other unique *.properties files and load that
one as follows
Properties props = new Properties();
ClassLoader myLoader = this.getClass().getClassLoader();
props.load(myLoader.getResourceAsStream("amq.properties"));
javax.naming.Context ctx = new InitialContext(props);
See the attached sample jndi.properties file
http://www.nabble.com/file/p16959605/jndi.properties jndi.properties
Hope this helps.
Joe
Goto www.ttmsolutions.com for a free ActiveMQ user guide
DA wrote:
>
> i have created ActiveMQConnectionFactory and it is working .But i want
> the code to be generic so that even if i change messaging from activemq to
> some other thing my code should work fine with out any changes.
>
>
> James.Strachan wrote:
>>
>> From an external client its often easier to just create an
>> ActiveMQConnectionFactory rather than use JNDI. Or use Spring
>>
>> 2008/4/29 DA <[EMAIL PROTECTED]>:
>>>
>>> Hi all,
>>> My application runs on jboss and i configured activewq for
>>> messsaging.everything is working fine messaging r flowing fine.Now i
>>> want to
>>> send message to this queue from an external client a main program.
>>> i created the initialcontext with the properties from jboss
>>>
>>> java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
>>> java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
>>>
>>> now when i did a lookup for connectionfatory it is returning me null.
>>> On
>>> debugging it i found that it actually found the connectionfactory but
>>> in
>>> NamingManager.getObjectInstance at
>>>
>>> factory = getObjectFactoryFromReference(ref, f);
>>> if (factory != null) {
>>> return factory.getObjectInstance(ref, name, nameCtx,
>>> environment);
>>> }
>>>
>>> it is returning null. Before going there, ref is holding the
>>> connectionfactory instance.
>>>
>>> i observed that factory is
>>> "org.jboss.util.naming.NonSerializableFactory"
>>>
>>> in that factory.getObjectInstance it is looking for
>>> connectionfactoryName
>>> in a map and simply returning null from there.
>>>
>>> can any one tell me what is happening there and what is wrong in my
>>> code.
>>>
>>> Thanks in advance.
>>> DA
>>> --
>>> View this message in context:
>>> http://www.nabble.com/sending-message-from-an-external-client-tp16956671s2354p16956671.html
>>> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>>>
>>>
>>
>>
>>
>> --
>> James
>> -------
>> http://macstrac.blogspot.com/
>>
>> Open Source Integration
>> http://open.iona.com
>>
>>
>
>
--
View this message in context:
http://www.nabble.com/sending-message-from-an-external-client-tp16956671s2354p16959605.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.