4 Replies Latest reply on Dec 9, 2014 3:27 AM by tibu

    How to lookup ejb in cluster on specific node

    tibu

      Hi!

       

      We recently asked how to lookup an ejb from a remote host and were told, that it is best practice now to use EjbClientContext instead of direct JNDI lookup.

      As a result our lookup code looks something like this, now:

       

      final Properties ejbProperties = new Properties();

      ejbProperties.put("remote.connection.default.host", ip);

      ejbProperties.put("remote.connection.default.port", port);

      <...>

      final EJBClientConfiguration ejbClientConfiguration = new PropertiesBasedEJBClientConfiguration(ejbProperties);

      final ConfigBasedEJBClientContextSelector selector = new ConfigBasedEJBClientContextSelector(ejbClientConfiguration);

      EJBClientContext.setSelector(selector);

      StatelessEJBLocator<T> locator = new StatelessEJBLocator<T>(type, app, module, bean, distinct);

      EJBClient.createProxy(locator)

       

      This code is used in multiple threads concurrently and works fine.

      We now want to lookup a singleton on a specific node (as a workaround for missing HA singletons...), so we have to change the ip and port for single lookups.

       

      How do you lookup EJBs from multiple servers with one EJBClientContext? Or is it possible to keep multiple EJBClientContexts somehow?

       

      Any hints would be great,

      Tibu

        • 1. Re: How to lookup ejb in cluster on specific node
          tibu

          Just wondering, is it even possible to lookup a ejb on a specific node in the cluster?

           

          We do this on one node, to look up ejb proxy on another node:

           

          Properties prop = new Properties();

          prop.put("remote.connections", "ejb");

          prop.put("remote.connection.ejb.host", host);

          prop.put("remote.connection.ejb.port", port);

          prop.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", "false");

          prop.put("remote.connection.ejb.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS", "false");

          prop.put("org.jboss.ejb.client.scoped.context", "true");

          InitialContext ct = new InitialContext(prop);

          Object res = ct.lookup(jndiName);

           

          This always returns a proxy for the current node not the remote one. We were hoping, that the scoped.context would serve exactly this purpose?

           

          Is there a known bug with this in 7.2.0.Final?

          • 2. Re: How to lookup ejb in cluster on specific node
            wdfink

            What you try to do? Lookup a remote EJB inside of an EJB?

            A scoped context has several issues, i.e. you need to use *.close() after use otherwise you will run into a connection leak.

             

            Could you describe what you try to achieve?

            • 3. Re: How to lookup ejb in cluster on specific node
              tibu

              Hi,

               

              we want to achieve this:

               

              - "Mark" one node of the cluster as master using a HA SingletonService as described in the cluster-ha-singleton quickstart

              - Deploy our former cluster singletons as node singletons

              - Use only the node singleton on the "master" by checking on which node the service is running

               

              So this is what we do:

              1) have the service running and returning its ip, port and node

              2) access it through a regular SLSB via injection

              3) ask this SLSB for the master connection (ip/port/node)

              4) connect to the desired node singleton on the cluster node returned by our master service

               

              We are struggeling with step 4, which we are trying to solve as described before. The problem is this:

              - Cluster with two nodes (A) and (B)

              - (B) is started first and running our master service

              - (A) wants to access a singleton and acquires the connection information from (B)

              - When we construct a InitialContext with this information, the lookup returns a proxy for the singleton on (A)

               

              We tried to disable mod-cluster by setting a simple load provider and by completly removing the subsystem configurations, but had no success.

              We also tried multiple variations of properties, but as far as I know, thos that I posted before should be the right ones...

               

              Any hint/link/guide would be awesome,

              Tibu

              • 4. Re: How to lookup ejb in cluster on specific node
                tibu

                We now switched to Wildfly 8.2.0 but the behavior is still the same. If anybody sees our error here or has some suggestion, please let me know!