[jboss-user] [Clustering/JBoss] - Re: How do servlets communicate with session beans across cl
do-not-reply at jboss.com
Sun Mar 30 08:53:03 EDT 2008
Inside your servlet, you need to do a JNDI lookup to the other cluster. Probably best thing is to use HA-JNDI with autodiscovery enabled so you aren't forced to statically list the JNDI hostnames/ports of the ejb cluster members:
| Properties p = new Properties();
| p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
| p.put(Context.URL_PKG_PREFIXES, "jboss.naming:org.jnp.interfaces");
| // Ensure we only find servers on the "EJBPartition"
| p.put("jnp.partitionName", "EJBPartition");
| Context ctx = new InitialContext(p);
| MyEJB ejb = (MyEJB) ctx.lookup("myEjbName");
See also http://wiki.jboss.org/wiki/Wiki.jsp?page=JBossHAJNDIUseCluster . Note that the examples on that page describe using "localhost:1100" which is based on the idea you want to find the HA-JNDI for the same cluster the client is in. If you were to use the jboss-web.xml resource-ref mapping described on that page, for the jndi-name element you would have to replace localhost:1100 with the hostname:port of *one* of the "EJBPartition" servers. Problem with doing that is if that server isn't running for some reason, you won't be able to find any of the other servers and can't do the lookup, even though other servers in the EJBPartition are running. To avoid that problem, don't try and use resource-ref mapping; just do the lookup programatically as shown above.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4139930#4139930
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4139930
More information about the jboss-user