Reputation: 5915
I want to have a bean 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:
C
which both A
and B
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 have A1
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 the Global
not portable jndi.
I would imagine some configuration in each app server would allow me to configure which other "neighbours" it should query for jndi remote beans.
Hope that gives a clue to someone out there.
Thanks,
Ittai
Upvotes: 3
Views: 3279
Reputation: 2071
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.
Upvotes: 0
Reputation: 2183
With 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
Upvotes: 3
Reputation: 5485
Upvotes: 2