geronimo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Jencks <david_jen...@yahoo.com>
Subject Re: JNDI Lookup
Date Tue, 08 Aug 2006 19:35:57 GMT

On Aug 8, 2006, at 12:20 PM, avin98 wrote:

>
> Hi,
>
> I have 2 Geronimo servers running on different boxes ...with the same
> application resources.
>
> I have a JMS Queue & a JMS Connection factory running on Box1 & Box2.
>
> From Box 1, I try to connect to a JMS resource on Box 2, it fails.
>
> Here is my code
>
> public Queue getRequestQueue(String hostName) {
>
>         if(hostName == null || hostName.length()==0)
>             return getRequestQueue();
>
>         Hashtable env = new Hashtable();
>         env.put(Context.INITIAL_CONTEXT_FACTORY,
> "org.activemq.jndi.ActiveMQInitialContextFactory");
>         env.put(Context.PROVIDER_URL, "tcp://server2:61616");
> 		 env.put(Context.SECURITY_PRINCIPAL,"geronimo");
> 			env.put(Context.SECURITY_CREDENTIALS,"geronimo");
>
> 		System.out.println("| ..........................................  
> |");
> 		System.out.println("| The Hostname getRequestQueue for connection
> is:"+hostName);
> 		System.out.println("| ..........................................  
> |");
>
>         try {
>             InitialContext naming = new InitialContext(env);
>             return (Queue) naming.lookup("Queue1");
>         } catch(NamingException e){
>             e.printStackTrace();
>             return null;
>         }
>     }
>
>
> I always get the Queue1 object which is bound to Server1 instead of  
> getting
> the object bound to Server2.
>
> Is there anything i am doing wrong here ?

There might be some way to get this to work, but it's not the j2ee  
way to do it.

I think you want to decide to run the amq broker on either machine 1  
or machine 2, but not both.  You can turn it off by adding  
load="false" in config.xml or through the console.

Then you want  to deploy the amq rar on both machines, with both rars  
pointing to the same broker (this will mean at least one rar is using  
a non-vm trasport)

The geronimo rar plan should include the connection factory you need  
and any admin objects (queues and topics) needed on the machine the  
rar is deployed on (apparently in your case Queue1).

Your application should declare that it's going to use the connection  
factory using a resource-ref and the admin objects using message- 
destination-refs (or resource-env-refs).

Then use

new InitialContext().lookup("java:comp/env/Queue1");

  or similar: do not supply an env to new InitialiContext().

thanks
david jencks

>
> -- 
> View this message in context: http://www.nabble.com/JNDI-Lookup- 
> tf2074678.html#a5713223
> Sent from the Apache Geronimo - Users forum at Nabble.com.
>


Mime
View raw message