2
votes

I am trying to make remote calls to multiple servers running on one instance of JBoss EAP 6 from a client server running on a separate instance of JBoss EAP 6. I have configured for JBoss-to-JBoss remote communication, and have read about scoped EJB client contexts, but the two do not appear to be compatible. Currently, I have two EJB Receivers configured (one for each remote server), but it appears when I try to make a remote call, the initialized Context randomly selects the EJB Receiver it will use. It would seem reasonable that I can force which EJB Receiver is used when the Context is initialized if I have the remote ip and port, or the remote connection name, but alas, I don't know the the secret handshake.

host.xml:

<security-realm name="ejb-security-realm">
    <server-identities>
        <secret value="ZWpiUEBzc3cwcmQ="/>
    </server-identities>
</security-realm>

domain.xml:

<subsystem xmlns="urn:jboss:domain:remoting:1.2">
                <connector name="remoting-connector" socket binding="remoting" security-realm="ApplicationRealm"/>
                <outbound-connections>
                    <remote-outbound-connection name="remote-ejb-connection" outbound-socket-binding-ref="mpg1-app1" username="ejbuser" 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="remote-ejb-connection2" outbound-socket-binding-ref="mpg2-app1" username="ejbuser" security-realm="ejb-security-realm">
                        <properties>
                            <property name="SASL_POLICY_NOANONYMOUS" value="false"/>
                            <property name="SSL_ENABLED" value="false"/>
                        </properties>
                    </remote-outbound-connection>
                </outbound-connections>
            </subsystem>
...
<socket-binding-group name="full-sockets" default-interface="public">
            ...
            <socket-binding name="remoting" port="44447"/>
            <outbound-socket-binding name="mpg1-app1">
                <remote-destination host="localhost" port="44452"/>
            </outbound-socket-binding>
            <outbound-socket-binding name="mpg2-app1">
                <remote-destination host="localhost" port="44453"/>
            </outbound-socket-binding>
</socket-binding-group>

jboss-ejb-client.xml

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

The remote call:

Context ctx = null;

final Properties props = new Properties();

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

try {

ctx = new InitialContext(props);
MyInterfaceObject ourInterface = ctx.lookup("ejb:" + appName + "/" + moduleName + "/" + beanName + "!" + viewClassName);

ourInteface.refreshProperties();//remote method call

}

Any Help would be greatly appreciated!

1

1 Answers

0
votes

have you try cluster-node-selector

jboss-ejb-client.xml

  <!-- if an outbound connection connect to a cluster a list of members is provided after successful connection.
To connect to this node this cluster element must be defined.
-->
   <clusters>
     <!-- cluster of remote-ejb-connection-1 -->
     <cluster name="ejb" security-realm="ejb-security-realm-1" username="test" cluster-node-selector="org.jboss.as.quickstarts.ejb.clients.selector.AllClusterNodeSelector">
        <connection-creation-options>
           <property name="org.xnio.Options.SSL_ENABLED" value="false" />
           <property name="org.xnio.Options.SASL_POLICY_NOANONYMOUS" value="false" />
        </connection-creation-options>
      </cluster>
   </clusters>
  </client-context>
</jboss-ejb-client>

Selector Implementation

    @Override
            public String selectNode(final String clusterName, final String[] connectedNodes, final String[] availableNodes) {
                    if (availableNodes.length == 1) {
                            return availableNodes[0];
                    }
                    // Go through all the nodes and point to the one you want
                    for (int i = 0; i < availableNodes.length; i++) {
                            if (availableNodes[i].contains("someoneYouInterestIn")) {
                                    return availableNodes[i];
                            }
                    }

                    final Random random = new Random();
                    final int randomSelection = random.nextInt(availableNodes.length);
                    return availableNodes[randomSelection];
            }

For more information you can check https://access.redhat.com/documentation/en/red-hat-jboss-enterprise-application-platform/7.0/developing-ejb-applications/chapter-8-clustered-enterprise-javab