You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by JohnF <Ma...@desy.de> on 2007/05/18 07:31:35 UTC

How to define properties for Topics and Queues

Hello,

I tried to use JNDI and the lookup() methode to get a topic for a client.

            properties = new Hashtable<String, String>();
            
            properties.put(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.activemq.jndi.ActiveMQInitialContextFactory");

            Context context = new InitialContext(properties);
            
            ConnectionFactory connectionFactory =
(ConnectionFactory)context.lookup("ConnectionFactory");

            properties.put(Context.PROVIDER_URL, "tcp://localhost:61616");

           Topic destination = (Topic)context.lookup("NAME_OF_TOPIC");

It failed and I got the NameNotFoundException. If I added the following
line, it does work:

            properties.put("topic.NAME_OF_TOPIC", "NAME_OF_TOPIC");

I do not want to use a property file that is stored in the classpath. How do
I have to configure a topic or a queue to avoid defining the Name of the
destination for JNDI in the code of the client?

Thank you

Regards,
Markus
-- 
View this message in context: http://www.nabble.com/How-to-define-properties-for-Topics-and-Queues-tf3775859s2354.html#a10676799
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: How to define properties for Topics and Queues

Posted by James Strachan <ja...@gmail.com>.
On 5/18/07, MarkusJ <Ma...@desy.de> wrote:
>
>
>
> James.Strachan wrote:
> >
> > On 5/18/07, JohnF <Ma...@desy.de> wrote:
> >>
> >> Hello,
> >>
> >> I tried to use JNDI and the lookup() methode to get a topic for a client.
> >>
> >>             properties = new Hashtable<String, String>();
> >>
> >>             properties.put(Context.INITIAL_CONTEXT_FACTORY,
> >> "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
> >>
> >>             Context context = new InitialContext(properties);
> >>
> >>             ConnectionFactory connectionFactory =
> >> (ConnectionFactory)context.lookup("ConnectionFactory");
> >>
> >>             properties.put(Context.PROVIDER_URL,
> >> "tcp://localhost:61616");
> >>
> >>            Topic destination = (Topic)context.lookup("NAME_OF_TOPIC");
> >>
> >> It failed and I got the NameNotFoundException. If I added the following
> >> line, it does work:
> >>
> >>             properties.put("topic.NAME_OF_TOPIC", "NAME_OF_TOPIC");
> >>
> >> I do not want to use a property file that is stored in the classpath. How
> >> do
> >> I have to configure a topic or a queue to avoid defining the Name of the
> >> destination for JNDI in the code of the client?
> >
> > You could load the properties file from some remote resource (file
> > server, web server, database). Or you could use some other JNDI
> > provider if you want (Sun's or one from your J2EE container) - which
> > amounts to the same thing but adds tons of work usually.
> >
> > Or use spring and put the creation of the destinations in your
> > spring.xml. Or just ditch JNDI/spring entirely and use the JMS API to
> > create the topics you want?
> >
> > --
> > James
> > -------
> > http://macstrac.blogspot.com/
> >
> >
>
> Hello James,
>
> thank you for answer. My hope was, that I can use the topic element of the
> configuration file. I have found the description of the topic element  in
> the reference page . The topic element has got one property called
> 'properties'. The description says: 'Get the properties from this instance
> for storing in JNDI.'.
>
> Is ist not possible to define the JNDI name of the topic at this place? How
> do I have to do it(the format of the entry)?

No. You put object into JNDI; so you can create any JNDI provider and
add ActiveMQTopic and ActiveMQQueue objects to JNDI - in any way you
like. Though a Topic doesn't have a magic way to auto-discover a JNDI
provider and add itself automatically.

I don't really follow your reasoning; there's already a properties
file (the jndi.properties file) which can create destinations &
register them in JNDI - why don't you wanna use it?

-- 
James
-------
http://macstrac.blogspot.com/

Re: How to define properties for Topics and Queues

Posted by MarkusJ <Ma...@desy.de>.


James.Strachan wrote:
> 
> On 5/18/07, JohnF <Ma...@desy.de> wrote:
>>
>> Hello,
>>
>> I tried to use JNDI and the lookup() methode to get a topic for a client.
>>
>>             properties = new Hashtable<String, String>();
>>
>>             properties.put(Context.INITIAL_CONTEXT_FACTORY,
>> "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
>>
>>             Context context = new InitialContext(properties);
>>
>>             ConnectionFactory connectionFactory =
>> (ConnectionFactory)context.lookup("ConnectionFactory");
>>
>>             properties.put(Context.PROVIDER_URL,
>> "tcp://localhost:61616");
>>
>>            Topic destination = (Topic)context.lookup("NAME_OF_TOPIC");
>>
>> It failed and I got the NameNotFoundException. If I added the following
>> line, it does work:
>>
>>             properties.put("topic.NAME_OF_TOPIC", "NAME_OF_TOPIC");
>>
>> I do not want to use a property file that is stored in the classpath. How
>> do
>> I have to configure a topic or a queue to avoid defining the Name of the
>> destination for JNDI in the code of the client?
> 
> You could load the properties file from some remote resource (file
> server, web server, database). Or you could use some other JNDI
> provider if you want (Sun's or one from your J2EE container) - which
> amounts to the same thing but adds tons of work usually.
> 
> Or use spring and put the creation of the destinations in your
> spring.xml. Or just ditch JNDI/spring entirely and use the JMS API to
> create the topics you want?
> 
> -- 
> James
> -------
> http://macstrac.blogspot.com/
> 
> 

Hello James,

thank you for answer. My hope was, that I can use the topic element of the
configuration file. I have found the description of the topic element  in
the reference page . The topic element has got one property called
'properties'. The description says: 'Get the properties from this instance
for storing in JNDI.'.

Is ist not possible to define the JNDI name of the topic at this place? How
do I have to do it(the format of the entry)?

Regards,
MarkusF
-- 
View this message in context: http://www.nabble.com/How-to-configure-topics-and-queues-for-using-with-JNDI%28_without_-a-jndi.properties-file%29-tf3775859s2354.html#a10678971
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: How to define properties for Topics and Queues

Posted by James Strachan <ja...@gmail.com>.
On 5/18/07, JohnF <Ma...@desy.de> wrote:
>
> Hello,
>
> I tried to use JNDI and the lookup() methode to get a topic for a client.
>
>             properties = new Hashtable<String, String>();
>
>             properties.put(Context.INITIAL_CONTEXT_FACTORY,
> "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
>
>             Context context = new InitialContext(properties);
>
>             ConnectionFactory connectionFactory =
> (ConnectionFactory)context.lookup("ConnectionFactory");
>
>             properties.put(Context.PROVIDER_URL, "tcp://localhost:61616");
>
>            Topic destination = (Topic)context.lookup("NAME_OF_TOPIC");
>
> It failed and I got the NameNotFoundException. If I added the following
> line, it does work:
>
>             properties.put("topic.NAME_OF_TOPIC", "NAME_OF_TOPIC");
>
> I do not want to use a property file that is stored in the classpath. How do
> I have to configure a topic or a queue to avoid defining the Name of the
> destination for JNDI in the code of the client?

You could load the properties file from some remote resource (file
server, web server, database). Or you could use some other JNDI
provider if you want (Sun's or one from your J2EE container) - which
amounts to the same thing but adds tons of work usually.

Or use spring and put the creation of the destinations in your
spring.xml. Or just ditch JNDI/spring entirely and use the JMS API to
create the topics you want?

-- 
James
-------
http://macstrac.blogspot.com/