PDA

View Full Version : dynamic lookup queue


pinglu
Sep 30th, 2004, 03:27 PM
Hi,
I have a application, which is like a message bridge, when my app get a message from other system, and send to different queue to be processed, my app did not know queue before get message, and admin can dynamic add queue. when I try to use spring, how to handle that.
in my old app, I can dynmic lookup the queue, but I don't know how in spring,
Any advance are welcome!

Ping

timmorrow
Sep 30th, 2004, 04:36 PM
You're going to want to use org.springframework.jms.support.destination.JndiDe stinationResolver (http://www.springframework.org/docs/api/org/springframework/jms/support/destination/JndiDestinationResolver.html)

You configure that with a JndiTemplate which itself is configured with the initial context and provider url of your JMS server.

Then, when you send to a named destination Spring will lookup the actual destination.

For example, define this is your bean context (this example uses TIBCO, obviously substitute the appropriate initial context and url):

<bean id="destinationResolver" class="org.springframework.jms.support.destination.JndiDe stinationResolver">
<property name="jndiTemplate"><ref bean="jmsJndiTemplate" /></property>
</bean>

<bean id="jmsJndiTemplate" class="org.springframework.jndi.JndiTemplate">
<property name="environment">
<props>
<prop key="java.naming.factory.initial">com.tibco.tibjms.naming.TibjmsInitialContextFactor y</prop>
<prop key="java.naming.provider.url">tcp://localhost:7222</prop>
</props>
</property>
</bean>


Then use it like this:

JmsTemplate102 jms = new JmsTemplate102();
jms.setDestinationResolver(destinationResolver); // came from bean context
jms.send("myDestinationName", new MessageCreator() {...});


The destination named "myDestinationName" will be looked-up from JNDI at runtime using the parameters you specified in your bean context file.

Tim

pinglu
Sep 30th, 2004, 04:52 PM
thanks!
very clean code & config
ping

nivas
Jan 25th, 2006, 02:35 PM
I will be getting 10 different messages,Depending on the value in my message, I need to send the message to one of the 10 queues. Can someone help me how can I setup the queues dynamically in spring context xml file . Thanks alot