12 Replies Latest reply on Jan 17, 2012 1:17 PM by jaikiran

    Remote ejb invocation between hosts

    akoledzhikov

      I'm running JBoss 7.1.0Beta in domain mode, and I've decided to try the new remote ejb invocation using jndi lookup. Drawing inspiration from the ancient texts provided here https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+client+using+JNDI , I did the following changes to my servers in host.xml :

       

      <servers>

              <server name="server-one" group="main-server-group">

                  <!-- server-one inherits the default socket-group declared in the server-group -->

                  <jvm name="default">

                 </jvm>

       

              </server>

              <server name="server-two" group="main-server-group" auto-start="true">

                  <!-- server-two avoids port conflicts by incrementing the ports in

                       the default socket-group declared in the server-group -->

                  <socket-binding-group ref="standard-sockets" port-offset="150"/>

                  <jvm name="default">

                      <heap size="64m" max-size="256m"/>

                  </jvm>

                   <system-properties>

                  <property name="jboss.ejb.client.properties.file.path" value="conf/remote-ejb.properties"/>

                 </system-properties>

              </server>

      </servers>

       

      And I blatantly copy/pasted the ejb-client.properties from your example - nothing changed there except the host name. Then I create my initial context and do the lookup/invocation like this:

       

            Hashtable env = new Hashtable();

            env.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");

            Context ctx  = new InitialContext(env);

       

           SingletonCounterAccess access = (SingletonCounterAccess)ctx.lookup("java:global/ejb/SingletonCounterRemote");

            access.increment();

       

      The following code is executed in a mdb deployed in server two, and the port, specified in conf/remote-ejb.properties is for server one. Unfortunately, the execution of access.increment() also happens in server two. Am I doing something wrong, or the mechanism for ejb calls between hosts is different?

      P.S. I've also tried passing some standard properties to the initial context:

       

           java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory

           java.naming.provider.url=jnp://localhost:4447

           java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces

       

      and tried to make the lookup without the remote-ejb properties, but failed with:

       

      javax.naming.CommunicationException: Could not obtain connection to any of these urls: localhost:4447 [Root exception is javax.naming.CommunicationException: Failed to retrieve stub from server localhost:4447 [Root exception is java.io.StreamCorruptedException: invalid stream header: 0000000C]]

        • 1. Re: Remote ejb invocation between hosts
          jaikiran

          SingletonCounterAccess access = (SingletonCounterAccess)ctx.lookup("java:global/ejb/SingletonCounterRemote");

                access.increment();

          That's not a JNDI name for remote invocations. The document that you are referring to has the details on what JNDI names to use for invocations from a remote client. It should be based on the ejb: namespace as explained that document.

          • 2. Re: Remote ejb invocation between hosts
            akoledzhikov

            So, I even if I've bound a remote interface to that jndi :

             

                 @Stateless

                 @Asynchronous

                 @EJB(name = "java:global/ejb/SingletonCounterRemote", beanInterface = SingletonCounterAccess.class)

                 public class SingletonCounter

                     implements SingletonCounterAccess

             

                 @Remote

                 public interface SingletonCounterAccess

             

            I should use the portable jndi name syntax for remote access ("ejb:EntityEJBTest-ear/EntityEJBTest-ejb//SingletonCounter!test.singleton.SingletonCounterAccess" - double slash because I have no distinct name for this ejb?)?

            Also, shouldn't I specify in some way that we are searching in the context of the other server? In the increment() method I have simple system.out printing, and it still claims that I've called the method in server-two.

            P.S. Thanks for the fast answer!

            • 3. Re: Remote ejb invocation between hosts
              prasad.deshpande

              Alexander Koledzhikov wrote:

               

              I should use the portable jndi name syntax for remote access ("ejb:EntityEJBTest-ear/EntityEJBTest-ejb//SingletonCounter!test.singleton.SingletonCounterAccess" - double slash because I have no distinct name for this ejb?)?

              You can omit that double slash, just a single one would work.. it did for me..

              • 4. Re: Remote ejb invocation between hosts
                mreasy

                Won't this make clients dependent upon EJB implementations?

                I currently have these bindings:

                 

                java:global
                 org.jboss.as.naming.NamingContext ejb
                  com.companyname.projectname.ejb.SBusinessLogicAccessEJB$$$view6 SBusinessLogicAccess
                 org.jboss.as.naming.NamingContext projectname-EAR
                  org.jboss.as.naming.NamingContext projectname-ejb
                   com.companyname.projectname.ejb.SBusinessLogicAccessEJB$$$view6 SBusinessLogicAccessEJB
                   com.companyname.projectname.ejb.SBusinessLogicAccessEJB$$$view6 SBusinessLogicAccessEJB!com.companyname.projectname.ejb.SBusinessLogicAccessEJB
                
                

                 

                where SBusinessLogicAccess is my remote interface, which I like to access.

                 

                Now this seems to be impossible (or I am missing a syntax hint), instead I can only do a look-up using:

                ejb:projectname-EAR/projectname-ejb/SBusinessLogicAccessEJB!com.companyname.projectname.ejb.SBusinessLogicAccessEJB
                

                to get the implementation, but this will throw a ClassNotFoundException if the client only knows about the Interface.

                • 5. Re: Remote ejb invocation between hosts
                  jaikiran

                  Rico Neubauer wrote:

                   

                  Won't this make clients dependent upon EJB implementations?

                  ...

                  Now this seems to be impossible (or I am missing a syntax hint), instead I can only do a look-up using:

                  See http://community.jboss.org/message/637338#637338

                  • 6. Re: Remote ejb invocation between hosts
                    mreasy

                    jaikiran pai schrieb:

                     

                    See http://community.jboss.org/message/637338#637338

                    Isn't that mainly considering the name pattern (which I also think needs improvements), but would nevertheless access the implementing class directly?

                    May main concern was how to access the remote interface I explicitely bound to java:global/ejb/SBusinessLogicAccess in my example.

                    • 7. Re: Remote ejb invocation between hosts
                      jaikiran

                      Rico Neubauer wrote:

                       

                      Isn't that mainly considering the name pattern (which I also think needs improvements), but would nevertheless access the implementing class directly?

                      May main concern was how to access the remote interface I explicitely bound to java:global/ejb/SBusinessLogicAccess in my example.

                      Sorry, I'm not understanding the question Are you saying you are not able to reference the remote interface of the bean from your client? Do you have those interfaces in a jar on the client classpath?

                      • 8. Re: Remote ejb invocation between hosts
                        mreasy

                        jaikiran pai schrieb:

                         

                        Sorry, I'm not understanding the question Are you saying you are not able to reference the remote interface of the bean from your client? Do you have those interfaces in a jar on the client classpath?

                        I can in the meantime Problem was, that only the no-interface view was exported (see my JNDI dump above). Now with exposed remote-interface-view it works as expected.

                        To answer your question: Yes, remote interface classes are in an own JAR (a OSGi-bundle exactly), EJB-implementation class is in an EAR/ejb-jar.

                        • 9. Re: Remote ejb invocation between hosts
                          jaikiran

                          Rico Neubauer wrote:

                           

                          I can in the meantime Problem was, that only the no-interface view was exported (see my JNDI dump above). Now with exposed remote-interface-view it works as expected.

                          Ah ok, good to know

                          • 10. Re: Remote ejb invocation between hosts
                            akoledzhikov

                            Sorry to bump the thread after such a long time, but my initial question kind of remained unanswered...

                            So how do I specify that I want to lookup and work with an ejb from server2 when I'm in server1 (they're both in the same group and have the same ejbs/bindings)?

                            Also, I'd really like to try the new EJB client API you've mentioned in the remote invocation guide. Any chance it's guide is published any time soon?

                            • 11. Re: Remote ejb invocation between hosts
                              jaikiran

                              Alexander Koledzhikov wrote:

                               

                               

                              So how do I specify that I want to lookup and work with an ejb from server2 when I'm in server1 (they're both in the same group and have the same ejbs/bindings)?

                              I'll writeup an example later tonight or tomorrow.

                               

                               

                              Alexander Koledzhikov wrote:

                               

                              Also, I'd really like to try the new EJB client API you've mentioned in the remote invocation guide. Any chance it's guide is published any time soon?

                              I've been planning to complete that documentation but given the other work that keeps accumulating, I end up pushing this out. I'm not sure if I can complete this by CR1, but it'll be surely be ready by 7.1.0.Final.

                              • 12. Re: Remote ejb invocation between hosts
                                jaikiran

                                I've just added the relevant documentation. See this post for more details https://community.jboss.org/message/647228#647228