2 Replies Latest reply on Sep 8, 2012 3:00 AM by jaikiran

    Re: Remote EJB connections from one server to several servers

    fmessiaen

      Thank you very much for your help, Jaikiran PAI.

       

      I have a better understanding of the usage of the distinct name for the EJB invokation.

       

      I put a jboss-app.xml file in the META-INF directory of the EAR. I dynamicaly put the server name in the distinct-name tag :

       

       <?xml version="1.0" encoding="UTF-8"?>
      <!--
        ~ JBoss, Home of Professional Open Source.
        ~ Copyright 2012, Red Hat, Inc., and individual contributors
        ~ as indicated by the @author tags. See the copyright.txt file in the
        ~ distribution for a full listing of individual contributors.
        ~
        ~ This is free software; you can redistribute it and/or modify it
        ~ under the terms of the GNU Lesser General Public License as
        ~ published by the Free Software Foundation; either version 2.1 of
        ~ the License, or (at your option) any later version.
        ~
        ~ This software is distributed in the hope that it will be useful,
        ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
        ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
        ~ Lesser General Public License for more details.
        ~
        ~ You should have received a copy of the GNU Lesser General Public
        ~ License along with this software; if not, write to the Free
        ~ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
        ~ 02110-1301 USA, or see the FSF site: http://www.fsf.org.
        -->
      <jboss-app xmlns="http://www.jboss.com/xml/ns/javaee"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/noschema/jboss-app_5_0.xsd"
                 version="5.0"
                 id="jboss-app-id">
          <distinct-name>${jboss.server.name}</distinct-name>
      </jboss-app>
      

       

      This way (without replacing the jboss.server.name property in that file), the content of the EAR file remains the same and the client only has to set in the distinct name the name of the server it wants to connect to.

       

      I tested it with the following code in the doGet method of my servlet:

      Greeter greeter_pcfme =  (Greeter) context.lookup("ejb:myapp/myejb/pc-fme/GreeterBean!" + org.myapp.ejb.Greeter.class.getName());
      final String greeting_pcfme = greeter_pcfme.greet("fme");
      Greeter greeter_pcfme2 =  (Greeter) context.lookup("ejb:myapp/myejb/pc-fme2/GreeterBean!" + org.myapp.ejb.Greeter.class.getName());
      final String greeting_pcfme2 = greeter_pcfme2.greet("fme");
      response.getWriter().append("<html><body>");
      response.getWriter().append("Received greeting: " + greeting_pcfme);
      response.getWriter().append("<br/>");
      response.getWriter().append("Received greeting: " + greeting_pcfme2);
      response.getWriter().append("</body></html>");
      
      

       

      And I got the following result each time I call the servlet :

       

      Received greeting: Hello fme, have a pleasant day! from pc-fme
      Received greeting: Hello fme, have a pleasant day! from pc-fme2
      

       

      It is exactly the result we expect.

       

      I have one more related question : can we declared the list of ejb receivers whitout the jboss-ejb-client.xml file in the EAR file ? Is it possible to declared a default list of ejb receivers in a standalone.xml/domain.xml file ?

      This is to avoid a "branch" JBoss server to connect uselessly to others "branch" JBoss servers, as no data has to be directly exchanged between "branch" JBoss servers.

       

      Best regards,

       

      François