This content has been marked as final.
Show 1 reply
-
1. Re: EJB Remote Client - reconnect - how to
jaysensharma Oct 26, 2015 5:03 AM (in response to nikiwalz)Hello Niki,
You are using remoting based approach to lookup EJBs which will not work in case of reconnect You should rather try using the EJB client API approach. Please try the following file in your EJB Client jar
jboss-ejb-client.properties
====================
remote.connections=one remote.connection.one.host=localhost remote.connection.one.port=8080 remote.connection.one.username=ejbUserOne remote.connection.one.password=ejbPasswordOne@123 remote.connection.one.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false
Client.java
========
package client; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import java.util.Properties; import ejb.one.CallerRemote; public class Client { public static void main(String ar[]) throws Exception { Context context=null; try { Properties props = new Properties(); props.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming"); context = new InitialContext(props); System.out.println("\n\tGot initial Context: "+context); } catch (Exception e) { e.printStackTrace(); } CallerRemote remote=(CallerRemote)context.lookup("ejb:TestEAR/remoteEjbOne/CallerBean!ejb.one.CallerRemote"); for (int i = 0; i <= 300; i++) { try { System.out.println("\n\t remote.testMethod(\"MiddlewareMagic!!!\") = "+remote.testMethod("MiddlewareMagic!!!")); Thread.sleep(500); } catch(Exception e) { System.out.println("\n\tEXCEPTION: " + e.getMessage()); e.printStackTrace(); try{ Thread.sleep(500); } catch(InterruptedException ee) { ee.printStackTrace(); } } } } }
It (client) should automatically reconnect to the WildFly instance as soon as the WildFly becomes available.
NOTE: Restrictions for EJB's
If the remote-naming is used there are some restrictions as there is no full support of the ejb-client features.
- No loadbalancing, if the URL conatains multiple "remote://" servers there is no loadbalancing, the first available server will be used and only in case it is not longer available there will be a failover to the next available one.
- No cluster support. As a cluster needs to be defined in the jboss-ejb-client.properties this feature can not be used and there is no cluster node added
- No client side interceptor. The EJBContext.getCurrent() can not be used and it is not possible to add a client interceptor
- No UserTransaction support
- All proxies become invalid if .close() for the related Initalcontext is invoked, or the InitialContext is not longer referenced and gets garbage-collected. In this case the underlying EJBContext is destroyed and the conections are closed.
- It is not possible to use remote-naming if the client is an application deployed on another JBoss instance
Labels: