1 Reply Latest reply on Jun 1, 2012 1:53 AM by jaikiran

    Remote EJB connections from one server to several servers

    fmessiaen

      Hello everyone,

       

      We try to migrate an application from JBoss 4.2.3 to JBoss 7.1.1.

       

      Here are some of our constraints  :

      • The JBoss AS are connected in a star topology network. This means that one JBoss AS is the central one and is used as reference.
      • A "branch" JBoss AS must keep running even if it loses its connections with the central one. The users of the rich clients have to be able to keep on working, in such a case.
      • The same EAR application is deployed on every JBoss AS. It is a parameter of its configuration file that indicate if the local EAR application must act as the central one. The EAR file contains EJB jars, business jar and JMS   deployements xml files.
      • The central EAR application must be able to communicate with each "branch" application independantly and specificaly. I mean the business of the central application may have to send data to a specific "branch" application, not to the   other "branch" applications.
      • Most of the code must be JEE server independent : EJB jars and business jars used only standard JEE interfaces and classes. We add only one "JEE server client' jar for classes to define JNDI properties, to connect to JMX MBean server   and so on, for the target JEE server.

       

      We firstly modify the code of the EAR application for the new JEE6 standard and the code of the rich clients of the application to connect to the EAR via JMX, EJB and JMS (mainly topics). Data are well exchanged between the EAR   application and the rich clients. It works fine.

       

      When we try to exchange data between JBoss AS, it failed. After that, I found the document EJB invocations from a remote server instance.  I tried to adapt the example of the document in our case.

       

      So I create the 2 ears. I deployed myapp.ear on 2 JBoss AS on my local PC and I deployed client-app.ear on virtual machine which will act as our central JBoss AS. So I modify the example as follow :

       

      in the standalone-full.xml :

      <logger category="org.jboss.ejb">
          <level name="TRACE"/>
      </logger>
      
      <remote-outbound-connection name="pc-fme" outbound-socket-binding-ref="pc-fme-remote-ejb" username="fme" security-realm="ejb-security-realm">
           <properties>
                <property name="SASL_POLICY_NOANONYMOUS" value="false"/>
                <property name="SSL_ENABLED" value="false"/>
           </properties>
      </remote-outbound-connection>
      <remote-outbound-connection name="pc-fme2" outbound-socket-binding-ref="pc-fme2-remote-ejb" username="fme" security-realm="ejb-security-realm">
           <properties>
                <property name="SASL_POLICY_NOANONYMOUS" value="false"/>
                <property name="SSL_ENABLED" value="false"/>
           </properties>
      </remote-outbound-connection>
      
      <outbound-socket-binding name="pc-fme-remote-ejb">
           <remote-destination host="pc-fme" port="4447"/>
      </outbound-socket-binding>
      <outbound-socket-binding name="pc-fme2-remote-ejb2">
           <remote-destination host="pc-fme" port="4547"/>
      </outbound-socket-binding>
      

      and we add the jboss-ejb-client.xml in the EAR of the central JBoss

      <jboss-ejb-client xmlns="urn:jboss:ejb-client:1.0">
          <client-context>
              <ejb-receivers>
                  <remoting-ejb-receiver outbound-connection-ref="pc-fme"/>
                  <remoting-ejb-receiver outbound-connection-ref="pc-fme2"/>
              </ejb-receivers>
          </client-context>
      </jboss-ejb-client>
      

      With that level for the logger org.jboss.ejb, I read the following line in the log file : (each JBoss AS is running in standalone mode, I don't know if that information may matter)

       

      11:51:01,307 DEBUG [org.jboss.ejb.client.EJBClientContext] (http--0.0.0.0-8080-1) org.jboss.ejb.client.RandomDeploymentNodeSelector@10b4506 deployment node selector selected pc-fme node for appname=myapp,modulename=myejb,distinctname=
       ...
      11:52:15,204 DEBUG [org.jboss.ejb.client.EJBClientContext] (http--0.0.0.0-8080-1) org.jboss.ejb.client.RandomDeploymentNodeSelector@10b4506 deployment node selector selected pc-fme2 node for appname=myapp,modulename=myejb,distinctname=
       ...
      11:52:16,866 DEBUG [org.jboss.ejb.client.EJBClientContext] (http--0.0.0.0-8080-1) org.jboss.ejb.client.RandomDeploymentNodeSelector@10b4506 deployment node selector selected pc-fme node for appname=myapp,modulename=myejb,distinctname=
      

      Is there a way to select the node to connect to ? (The JBoss servers are not clustered)

       

      As the EAR file are supposed to be the same on each JBoss AS, can we declare the EJB receivers without the jboss-ejb-client.xml file ?

       

      Thank you for your answers.

       

      François

       

      Message was edited by: jaikiran pai - Fixed formatting

        • 1. Re: Remote EJB connections from one server to several servers
          jaikiran

          François, welcome to the forums!

          fmessiaen wrote:

           

          Is there a way to select the node to connect to ? (The JBoss servers are not clustered)

           

          The node to which the remote EJB invocation has to be directed to is identified by the combination of app-name/modulename/distinct-name/bean-name combination. Now if multiple nodes can handle the same bean packaged within the same application and if you want a specific node from those nodes to handle the invocation, then you'll have to assign a different "distinct-name" to the application deployed on that node and use that distinct-name in your lookup.

           

          For example, if you have a foo.ear containing bar.jar with HelloWorld EJB and node 1 and node 2 contain that .ear, then you can assign a different distinct-name (for example "node2-app") to the foo.ear in node 2 via the jboss-app.xml for EARs (for top level WARs it is jboss-web.xml and for top level EJB jars it's jboss-ejb3.xml) or set that distinct name at the EJB3 subsystem level (applies to all applications deployed on that server). Then in the client code where you know which node the invocation should go to, you'll just use the appropriate distinct-name (along with the app, module and bean name combinations) while looking up the bean and invoking on it.

           

          Here's an example on how to set the distinct-name in the application deployment descriptor https://github.com/jbossas/jboss-as/blob/master/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/distinctname/jboss-app.xml#L28