You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by John Fletcher <fl...@gmail.com> on 2011/05/20 14:22:26 UTC

How to dynamically create JNDI Context Resources

In my application I'm using a library which uses JNDI to locate JMS topics
and then operates with them.

I successfully configured JNDI references to the JMS topics like this in
Context.xml, and everything works nicely:

    <Resource name="jms/flex/TopicConnectionFactory"
              type="org.apache.activemq.ActiveMQConnectionFactory"
              description="JMS Connection Factory"
              factory="org.apache.activemq.jndi.JNDIReferenceFactory"
              brokerURL="tcp://localhost:61616"
              brokerName="activeMQBroker" />

    <Resource name="jms/gds1"
              type="org.apache.activemq.command.ActiveMQTopic"
              description="Discussion topic for GraniteDS"
              factory="org.apache.activemq.jndi.JNDIReferenceFactory"
              physicalName="test.gds1"
              />

The challenge is that the JMS topics I want to make available to the library
depend on some runtime information, i.e. I want my application to create the
JMS topics dynamically. Is there a way that I can create these JNDI
resources at runtime from my application instead of having to hard-code them
into Context.xml? I'm able to upgrade to Tomcat 7 if necessary.
I found this, not sure if it could solve my problem?
http://tomcat.apache.org/tomcat-7.0-doc/jndi-resources-howto.html#Adding_Custom_Resource_Factories
.

I'm no expert on JNDI so if there is an altogether better solution to my
problem I'm open to it.

John

Re: How to dynamically create JNDI Context Resources

Posted by John Fletcher <fl...@gmail.com>.
Thanks... I thought the answer was along those lines but the library I'm
using was constraining me to use JNDI. However I now looked into their
source code and found a clean way around JNDI. Your answer got me motivated
in the right direction, thankyou.

John

2011/5/23 Mikolaj Rydzewski <mi...@ceti.pl>

> On Mon, 23 May 2011 10:34:28 +0200, John Fletcher wrote:
>
>  The challenge is that the JMS topics I want to make available to the
>>> library depend on some runtime information, i.e. I want my application to
>>> create the JMS topics dynamically. Is there a way that I can create these
>>> JNDI resources at runtime from my application instead of having to
>>> hard-code
>>> them into Context.xml?
>>>
>>
> So why do you want to use JNDI still? You can call factory method yourself.
> Yes, this will tight you to specific JMS implementation. But do you plan to
> migrate to different JMS provider? With very little effort you can configure
> spring (is there anyone who does not use spring nowadays?) to hide direct
> factory calls.
>
> --
> Mikolaj Rydzewski <mi...@ceti.pl>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: How to dynamically create JNDI Context Resources

Posted by Mikolaj Rydzewski <mi...@ceti.pl>.
 On Mon, 23 May 2011 10:34:28 +0200, John Fletcher wrote:

>> The challenge is that the JMS topics I want to make available to the
>> library depend on some runtime information, i.e. I want my 
>> application to
>> create the JMS topics dynamically. Is there a way that I can create 
>> these
>> JNDI resources at runtime from my application instead of having to 
>> hard-code
>> them into Context.xml?

 So why do you want to use JNDI still? You can call factory method 
 yourself. Yes, this will tight you to specific JMS implementation. But 
 do you plan to migrate to different JMS provider? With very little 
 effort you can configure spring (is there anyone who does not use spring 
 nowadays?) to hide direct factory calls.

-- 
 Mikolaj Rydzewski <mi...@ceti.pl>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How to dynamically create JNDI Context Resources

Posted by John Fletcher <fl...@gmail.com>.
Resending this as it didn't arrive in my inbox... sorry if you received it
already...

2011/5/20 John Fletcher

> In my application I'm using a library which uses JNDI to locate JMS topics
> and then operates with them.
>
> I successfully configured JNDI references to the JMS topics like this in
> Context.xml, and everything works nicely:
>
>     <Resource name="jms/flex/TopicConnectionFactory"
>               type="org.apache.activemq.ActiveMQConnectionFactory"
>               description="JMS Connection Factory"
>               factory="org.apache.activemq.jndi.JNDIReferenceFactory"
>               brokerURL="tcp://localhost:61616"
>               brokerName="activeMQBroker" />
>
>     <Resource name="jms/gds1"
>               type="org.apache.activemq.command.ActiveMQTopic"
>               description="Discussion topic for GraniteDS"
>               factory="org.apache.activemq.jndi.JNDIReferenceFactory"
>               physicalName="test.gds1"
>               />
>
> The challenge is that the JMS topics I want to make available to the
> library depend on some runtime information, i.e. I want my application to
> create the JMS topics dynamically. Is there a way that I can create these
> JNDI resources at runtime from my application instead of having to hard-code
> them into Context.xml? I'm able to upgrade to Tomcat 7 if necessary.
> I found this, not sure if it could solve my problem?
> http://tomcat.apache.org/tomcat-7.0-doc/jndi-resources-howto.html#Adding_Custom_Resource_Factories
> .
>
> I'm no expert on JNDI so if there is an altogether better solution to my
> problem I'm open to it.
>
> John
>