6 Replies Latest reply on Apr 23, 2012 9:52 PM by gwwallace

    Session Bean To Session Bean Invocation

    foutjo

      Can anyone tell me how I would get setup a session bean to get access to another session bean from either the same server or another clusterd server?

      I have read lots of confusing threads on how this might be done but I can't seem to find a clear answer.

       

      Here is a my scenario:

       

      SLSB#1 (Not Clustered)  Deployed on Server#1

      SLSB#2 (Clustered) Deployed on Server#1/Server#2/Server#3

       

      Java Client                       Server #1                     Server #2                Server #3

      ---------------                       --------------                     -------------                 -------------

                                             SLSB#1                      SLSB#2                  SLSB#2 

                                             SLSB#2                

                                             

      1.  The java client can successfully get access to SLSB#1 using the following code along with the jboss-ejb-client.properties file:

       

               final Hashtable<String, String> jndiProperties = new Hashtable<String, String>();

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

               final Context context = new InitialContext(jndiProperties);

               final String appName = "";

               final String moduleName = "Server-Listener-EJB";

               final String distinctName = "";

               final String beanName = "Server_Listener";

               final String viewClassName = Server_ListenerINF.class.getName();

               String bean = "ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName

                     + "!" + viewClassName;

       

               Server_ListenerINF serverListener = (Server_ListenerINF) context.lookup(bean);

            

               adminReturned = serverListener.processAdminTran(adminObject);      

       

      2.  Now I want to have SLSB#1 get access to SLSB#2.

           Being that SLSB#2 is clustered here was the java code used to

           successfully access SLSB#2 using JBOSS 5.1.

       

               Properties p = new Properties();  

               p.put(Context.INITIAL_CONTEXT_FACTORY,  

                       "org.jnp.interfaces.NamingContextFactory");

               p.put(Context.URL_PKG_PREFIXES, "jboss.naming:org.jnp.interfaces");

              

               String partitionName = System.getProperty("jboss.partition.name", "clusterPartition2");

               p.put("jnp.partitionName", partitionName);         

                    

               try

               {

                  ctx = new InitialContext(p);

                  String s = "Background" + process.getBackgroundType() + "SessionBean/remote";

                  BackgroundTranSessionRemoteINF bean = (BackgroundTranSessionRemoteINF) ctx.lookup(s);

                  bean.process(backgroundData);

               }

               .....

       

      QUESTION:   How do accomplish the above using JBOSS-AS-7?

       

      I have read jaikiran pai document : EJB invocations from a remote server instance

      But I am still confused.  Not sure if this is what I should be doing or is there another way.

       

       

      I have be trying to resolve this issue since JBoss 7.0 was released.

      It took be a very long time to finally figure out how to get it to work in JBoss 5.1 and

      now I'm right back where I started from in JBoss 7.   Very frustrating:(

       

      Any help on this topic by the resident JBOSS Experts is greatly appreciated.

       

      Thanks.

        • 1. Re: Session Bean To Session Bean Invocation
          foutjo

          So can I do this or should I wait for version 8?

          • 2. Re: Session Bean To Session Bean Invocation
            gwwallace

            Hey Joseph,

             

            Server to Server EJB Invocation works fine - if you follow the docs - because the connectivity is specified in the config file. You can simply lookup your remote ejb

            with

             

            final Hashtable jndiProperties = new Hashtable();

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

             

            context = new InitialContext(jndiProperties);

             

            remoteBean = (RemoteBeanInterface) context.lookip("ejb:<app-name>/<module-name>/<distinct-name>/<bean-name>!<fully-qualified-classname-of-the-remote-interface>");

             

            after specifying

             

                <subsystem xmlns="urn:jboss:domain:remoting:1.1">
                    <connector name="remoting-connector" socket-binding="remoting"/>
                    <outbound-connections>
                        <remote-outbound-connection name="remote-ejb-connection" outbound-socket-binding-ref="remote-ejb">
                            <properties>
                                <property name="SASL_POLICY_NOANONYMOUS" value="false"/>
                                <property name="SSL_ENABLED" value="false"/>
                            </properties>
                        </remote-outbound-connection>
                    </outbound-connections>
                </subsystem>

             

            and inside the node

             

            <socket-binding-group name="standard-sockets" default-interface="public" port-offset="${jboss.socket.binding.port-offset:0}">

             

            put

             

                <outbound-socket-binding name="remote-ejb">
                    <remote-destination host="your remote ejb hostname" port="4447"/>
                </outbound-socket-binding>

             

             

            Unfortunately this doesnt handle clusters at all - as it wants to be tied to one server for the initial JNDI lookup.

             

            Can't find any documentation that explains how this is supposed to work......

             

            Let me know if you do...I've given up trying to use JBoss 7 for anything serious because of the deficiencies in cluster handling.

            Hopefully some of this will get fixed and documented soon as we are stuck on JBoss 4 until it does.

            • 3. Re: Session Bean To Session Bean Invocation
              foutjo

              Hey Graeme,

               

              Finally somebody who knows how to use this stuff.

              I knew I could count on you.

               

              Worked like a charm. 

              Your help is greatly appreciated.

               

              I too am anxiously awaiting the full support for round robin clustering in JBoss 7.

               

              Hopefully jaikiran pai will have something for us soon.  Jaikiran are you there?

               

              Take care and thanks again.

              • 4. Re: Session Bean To Session Bean Invocation
                jaikiran

                Joseph Fouts wrote:

                 

                I too am anxiously awaiting the full support for round robin clustering in JBoss 7.

                 

                The ability to plugin a custom load balancer implementation for directing invocations on clustered beans to different nodes is possible. We don't provide any out of the box implementation like round robin implementation. The implementation class name can be configured in jboss-ejb-client.xml of the application (for server side) or jboss-ejb-client.properties (for client side). The xsd for jboss-ejb-client.xml is here https://github.com/jbossas/jboss-as/blob/master/build/src/main/resources/docs/schema/jboss-ejb-client_1_1.xsd#L66 (also available in JBOSS_HOME/docs/schema folder of the distribution). Take a look at the cluster-node-selector attribute https://github.com/jbossas/jboss-as/blob/master/build/src/main/resources/docs/schema/jboss-ejb-client_1_1.xsd#L172.

                 

                Here's an example from a testcase https://github.com/jbossas/jboss-as/blob/master/testsuite/integration/manualmode/src/test/java/org/jboss/as/test/manualmode/ejb/client/cluster/jboss-ejb-client.xml

                • 5. Re: Session Bean To Session Bean Invocation
                  jaikiran

                  Graeme Wallace wrote:

                   

                   

                  Unfortunately this doesnt handle clusters at all - as it wants to be tied to one server for the initial JNDI lookup.

                   

                  Can't find any documentation that explains how this is supposed to work......

                   

                  You have got the initial part right. Like explained in this documentation https://docs.jboss.org/author/display/AS71/Clustered+EJBs once the initial node to connect to is known, the cluster topology will be sent back to the client. The client then auto-connects to the nodes within the cluster as and when appropriate. During auto connect, it requires certain configurations for the node (like security configurations) that have to be configured in the jboss-ejb-client.xml (if your client is a AS7 instance itself) or jboss-ejb-client.properties (for standalone clients).

                   

                  The jboss-ejb-client.xml xsd is here and allows you to configure the cluster configurations either at each node level or for all nodes within a named cluster  https://github.com/jbossas/jboss-as/blob/master/build/src/main/resources/docs/schema/jboss-ejb-client_1_1.xsd#L66

                   

                  Here's an example of jboss-ejb-client.xml from a testsuite which shows an example https://github.com/jbossas/jboss-as/blob/master/testsuite/integration/manualmode/src/test/java/org/jboss/as/test/manualmode/ejb/client/cluster/jboss-ejb-client.xml.

                   

                  Feel free to ask if you have more questions around this.

                  • 6. Re: Session Bean To Session Bean Invocation
                    gwwallace

                    I've tried to configure the above but I'm stuck on the JBoss to JBoss configuration.

                     

                    I've created the jboss-ejb-client.xml as follows

                     

                    <jboss-ejb-client xmlns="urn:jboss:ejb-client:1.1">

                        <client-context>

                            <ejb-receivers>

                                <remoting-ejb-receiver outbound-connection-ref="remote-ejb-connection"/>

                            </ejb-receivers>

                            <clusters>

                                <cluster name="ejb" max-allowed-connected-nodes="20" cluster-node-selector="com.xxi.framework.jbossaux.cluster.RoundRobinClusterNodeSelector" connect-timeout="5000" security-realm="PasswordRealm">

                                    <connection-creation-options>

                                        <property name="org.xnio.Options.SSL_ENABLED" value="false"/>

                                        <property name="org.xnio.Options.SASL_POLICY_NOANONYMOUS" value="true"/>

                                    </connection-creation-options>

                                </cluster>

                            </clusters>

                        </client-context>

                    </jboss-ejb-client>

                     

                    I know it gets picked up and read by JBoss - because if i put a dummy class name in for the cluster-node-selector it complains about ClassNotFound. (However i HAVE to put in a security-realm attribute and value otherwise the xml parsing code complains)

                     

                    JBoss starts successfully. I can do the lookup to the remote EJB and I can make a remote method call.

                    However, the class specified in the cluster-node-selector value never gets instantiated and obviously never gets called either.

                     

                    On startup the following messages are printed out from remoting

                     

                    21:42:30,865 INFO  [org.jboss.ejb.client.remoting.VersionReceiver] (Remoting "cmc5-104" task-4) Received server version 1 and marshalling strategies [river]

                    21:42:30,874 INFO  [org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver] (MSC service thread 1-6) Successful version handshake completed for receiver context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@148fc86f, receiver=Remoting connection EJB receiver [connection=Remoting connection <378fc5db>,channel=jboss.ejb,nodename=cmc5-101]} on channel Channel ID ef00ec9a (outbound) of Remoting connection 242d8a8c to cmc5-101.alpha.farecompare.com/192.168.12.161:4447

                    21:42:30,875 WARN  [org.jboss.ejb.client.remoting.ChannelAssociation] (Remoting "cmc5-104" task-1) Unsupported message received with header 0xffffffff

                     

                    It doesnt look like remoting is being told about the other node in the cluster - as if i run a standalone client i get

                     

                    INFO: JBoss Remoting version 3.2.4.GA

                    Apr 23, 2012 9:26:18 PM org.jboss.ejb.client.remoting.VersionReceiver handleMessage

                    INFO: Received server version 1 and marshalling strategies [river]

                    Apr 23, 2012 9:26:18 PM org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver associate

                    INFO: Successful version handshake completed for receiver context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@4ee993e, receiver=Remoting connection EJB receiver [connection=Remoting connection <cfed7c>,channel=jboss.ejb,nodename=cmc5-101]} on channel Channel ID d2dfe8e4 (outbound) of Remoting connection 35b4e829 to cmc5-101.alpha.farecompare.com/192.168.12.161:4447

                    Apr 23, 2012 9:26:18 PM org.jboss.ejb.client.remoting.ChannelAssociation$ResponseReceiver handleMessage

                    WARN: Unsupported message received with header 0xffffffff

                    Apr 23, 2012 9:26:18 PM org.jboss.ejb.client.remoting.VersionReceiver handleMessage

                    INFO: Received server version 1 and marshalling strategies [river]

                    Apr 23, 2012 9:26:18 PM org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver associate

                    INFO: Successful version handshake completed for receiver context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@4ee993e, receiver=Remoting connection EJB receiver [connection=Remoting connection <23cb7f34>,channel=jboss.ejb,nodename=cmc5-102]} on channel Channel ID f2c475f8 (outbound) of Remoting connection 2aa49512 to cmc5-102.alpha.farecompare.com/192.168.12.162:4447

                    Apr 23, 2012 9:26:18 PM org.jboss.ejb.client.remoting.ChannelAssociation$ResponseReceiver handleMessage

                    WARN: Unsupported message received with header 0xffffffff

                    Apr 23, 2012 9:26:18 PM org.jboss.ejb.client.EJBClient <clinit>

                    INFO: JBoss EJB Client version 1.0.6.CR1

                     

                    where it receives info on both nodes in the cluster.

                     

                    Am i missing another piece of the configuration for the server to server call to get clustering to work or is this a bug ?