EJB, Remoting between two application-servers (glassfish)
Foo
in host A
which is injected, by the @EJB
annotation to a bean Bar
in host B
.
Both these hosts are separate stand-alone instances of Glassfish-v3
.
When reading the Glassfish
docs I found a lot of info, some of it sounded a bit contradicting.
I understood that every bean has a global jndi named assigned to it and understood how it is constructed, What is the syntax for portable global JNDI names?. I also understood that the the declaration of Foo
in Bar
should be something of this sort (assuming FooRemote
is the remote business interface of Foo
and fooejb
is the its module): @EJB(lookup=java:global/fooejb/FooRemote) FooRemote foo
, this is based on this.
What I can't understand is where I tell host A
and host B
to get to know each other.
I saw a lot of examples for application clients and application servers but I wasn't able to find an example for such a scenario.
In this question a sun-web.xml
and Global-JNDI
is mentioned but I think that it's not EJB3.1 (since it's not Portable JNDI
) and I don't understand where this sun-web.xml
should reside (I'd like to avoid it if I can).
It is mainly different in two ways:
- There is no -Dorg.omg.CORBA.ORBInitialHost= param option (as far as I can see)
- Any solution should of course allow the inclusion of a third host
C
which bothA
andB
communicate with for different purposes.
I have a strong feeling I'm missing something basic here and I'd really appreciate pointers to what I'm missing.
BTW, I'd like to avoid as much as possible from descriptor files and such and leave most info on annotations and only the host ip's to config in the server.Edit:
I think another interesting aspect of this question is how load-balancing is used in this aspect, i.e. let's say I haveA1
and A2
servers which are the same, how will load-balancing occur with respect to routing the request from B
to either A1
or A2
Edit2:
I think this might be unrelated to ejb 3.1 but related to the basis on how to enable two application servers to see each other's jndi registry. I think this is unrelated to ejb 3.1 as it seems a similar problem exists in the 3.0 with theGlobal
not portable jndi.
I would imagine some configuration in each app server would allow开发者_StackOverflow中文版 me to configure which other "neighbours" it should query for jndi remote beans.
Hope that gives a clue to someone out there.
Thanks,
IttaiWith regards to EJB Load balancing you might like to take a look at this blog:
http://www.techpost.info/2010/12/ejb-load-balancer_7304.html
- As stated in one of the pages you link to, when using a cluster then you don't need extra configuration to get this to work. If you need load balancing etc. I'd imagine it is easier to set up a cluster up than doing it manually.
- sun-web.xml goes right next to web.xml in WEB-INF if you deploy it as a web project in .war file.
- I would think you should be able to get it right using: http://glassfish.java.net/javaee5/ejb/EJB_FAQ.html#cross-appserverremoteref and http://glassfish.java.net/javaee5/ejb/EJB_FAQ.html#mappingRemoteejbdependency
- I would have thought there must be an easy way to configure a EJB connector or Resource adaptor in glassfish itself using the administration console or editing the server.xml. But I can't find such a thing now.
We are using remote EJBs and it works fine.
First you'll need the EJB on "Host A" wich implements an interface whose class is present on both hosts.
//For host A + B
public interface FooClass {
public void theMethod();
}
//Only for host A
@Stateless
public class FooClassImpl implements FooClass {
public void theMethod(){//Code goes here}
}
Then you'll need to create (on Host B) a glassfish-web.xml in your WEB-INF directory, where you specify where a remote EJB is located:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app error-url="">
<ejb-ref>
<ejb-ref-name>RemoteEJBName</ejb-ref-name>
<jndi-name>corbaname:iiop:<servername or IP>:3700#java:global/<projectname>/FooClassImpl!com.test.foo.FooClass</jndi-name>
</ejb-ref>
</glassfish-web-app>
At the injection point on Host B you'll need to inject the EJB like this:
@EJB(name = "RemoteEJBName")
private FooClass theFooClassInstance;
I hope this will do the trick.
精彩评论