How to configure EJB Cluster Node Selector / Deployment Node Selector in EAP 7.1 and later
Environment
- Red Hat JBoss Enterprise Application Platform (EAP)
- 7.x
Issue
How to configure EJB Cluster Node Selector / Deployment Node Selector in EAP 7.1 and later?
Resolution
DeploymentNodeSelector is a selector which selects and returns a node, from among the passed eligible nodes, that can handle a specific deployment within a EJB client context. Node selection is only used when discovery yields nodes as a result of its query to locate an EJB. If discovery yields a URI or cluster, this mechanism is not used.
ClusterNodeSelector is a selector which selects and returns a node from the available nodes in a cluster. The EJBReceiver corresponding to the selected node will then be used to forward the invocations on a EJB. Typical usage of a ClusterNodeSelector involve load balancing of calls to various nodes in the cluster
Standalone client
wildfly-config.xml - EAP 7.2+
Note: For EAP 7.2 , make sure you are on the latest cumulative patch as there was a bug fixed in CP1 related to wildfly-config.xml and node selectors This content is not included.JBEAP-16185. EAP 7.3+ already has this fix.
Therefore, in EAP 7.2 CP1+ , the deployment-node-selector and cluster-node-selector can be configured in a standalone java application's wildfly-config.xml for example:
<?xml version="1.0" ?>
<configuration>
...
<jboss-ejb-client xmlns="urn:jboss:wildfly-client-ejb:3.2">
<connections>
<connection uri="remote+http://127.0.0.1:8080"/>
<connection uri="remote+http://127.0.0.1:8180"/>
</connections>
<invocation-timeout seconds="10"/>
<deployment-node-selector class="org.jboss.ejb.client.DummyNodeSelector" />
<cluster-node-selector class="org.jboss.ejb.client.DummyNodeSelector" />
<global-interceptors>
<interceptor class="org.jboss.ejb.client.DummyClientInterceptor"/>
<interceptor class="org.jboss.ejb.client.DummyClientInterceptor2"/>
</global-interceptors>
<max-allowed-connected-nodes nodes="15"/>
</jboss-ejb-client>
</configuration>
jboss-ejb-client.properties EAP 7.0 / 7.1+
The DeploymentNodeSelector and ClusterNodeSelector for a standalone Java client can be set using the legacy jboss-ejb-client.properties file like below:
endpoint.name=client-endpoint
...
remote.connection.node1.password=apppassword
deployment.node.selector=org.jboss.CustomDeploymentNodeSelector
...
remote.cluster.ejb.clusternode.selector=org.jboss.CustomClusterNodeSelector
Client running inside an application on another JBoss instance
The DeploymentNodeSelector and ClusterNodeSelector for a client running on another JBoss EAP instance can be set using the jboss-ejb-client.xml file below:
<jboss-ejb-client xmlns:xsi="urn:jboss:ejb-client:1.2" xsi:noNamespaceSchemaLocation="jboss-ejb-client_1_2.xsd">
<client-context deployment-node-selector="org.jboss.CustomDeploymentNodeSelector">
<ejb-receivers>
<remoting-ejb-receiver outbound-connection-ref="remote-ejb-connection-1" />
<remoting-ejb-receiver outbound-connection-ref="remote-ejb-connection-2" />
</ejb-receivers>
<clusters>
<cluster name="ejb" security-realm="ejb-security-realm" username="remote-user" cluster-node-selector="org.jboss.CustomClusterNodeSelector" />
</clusters>
</client-context>
</jboss-ejb-client>
Notes
- If there is only one remote connection, then the Deployment Node Selector will not be invoked since there is only one option
- If there are multiple remote connections that are not clustered, then the Deployment Node Selector is invoked
- If the client is connected to a node that is clustered, then the Cluster Node Selector will be invoked and not the Deployment Node Selector
- See the solution Why Deployment Node Selector is not being invoked in JBoss EAP 7? for more details on using both tags: Deployment Node Selector and Cluster Node Selector at the same time.
Root Cause
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.