2 Replies Latest reply on Mar 11, 2014 3:41 PM by vbchin2

    Connecting to remote ConnectionFactory and Queue

    jimdarkmagic

      Hi,

      I got a problem with lookup of a remote ConnectionFactory.

       

      On my JBoss 7.2.0 I have this code deployed as an ejb.

      package server;
      
      import javax.ejb.ActivationConfigProperty;
      import javax.ejb.MessageDriven;
      import javax.jms.Message;
      import javax.jms.MessageListener;
      
      @MessageDriven
      (
          activationConfig =  
          {
              @ActivationConfigProperty(propertyName="destination", propertyValue="queue/FibonacciQueue"),
              @ActivationConfigProperty(propertyName="destinationType", propertyValue="javax.jms.Queue"),
              @ActivationConfigProperty(propertyName="subscriptionDurability", propertyValue="NonDurable")
          }
      )
      public class FibonacciBean implements MessageListener
      {
        @Override
        public void onMessage(Message msg)
        {
          System.out.println(msg);
        }
      
      }
      
      
      

       

      The server is also giving me greenlight that everything is deployed and my queues are existent.

       

      17:52:52,916 INFO  [org.hornetq.core.server] (MSC service thread 1-5) HQ221009: Server is now live

      17:52:52,916 INFO  [org.hornetq.core.server] (MSC service thread 1-5) HQ221003: HornetQ Server version 2.3.0.CR1 (buzzzzz!, 122) [81c1c181-a930-11e3-8454-fba40b6c1c76]

      17:52:52,932 INFO  [org.hornetq.core.server] (ServerService Thread Pool -- 58) HQ221005: trying to deploy queue jms.queue.Fibonacci

      17:52:53,025 INFO  [org.jboss.as.jacorb] (MSC service thread 1-6) JBAS016328: CORBA Naming Service started

      17:52:53,041 INFO  [org.jboss.as.messaging] (ServerService Thread Pool -- 58) JBAS011601: Bound messaging object to jndi name java:/queue/FibonacciQueue

      17:52:53,041 INFO  [org.jboss.as.messaging] (ServerService Thread Pool -- 58) JBAS011601: Bound messaging object to jndi name java:jboss/exported/queue/FibonacciQueue

      17:52:53,057 INFO  [org.jboss.as.messaging] (ServerService Thread Pool -- 60) JBAS011601: Bound messaging object to jndi name java:/ConnectionFactory

      17:52:53,057 INFO  [org.jboss.as.connector.deployment] (MSC service thread 1-1) JBAS010406: Registered connection factory java:/JmsXA

      17:52:53,057 INFO  [org.jboss.as.messaging] (ServerService Thread Pool -- 59) JBAS011601: Bound messaging object to jndi name java:jboss/exported/jms/RemoteConnectionFactory

      17:52:53,103 INFO  [org.hornetq.ra] (MSC service thread 1-1) HornetQ resource adaptor started

      17:52:53,103 INFO  [org.jboss.as.connector.services.resourceadapters.ResourceAdapterActivatorService$ResourceAdapterActivator] (MSC service thread 1-1) IJ020002: Deployed: file://RaActivatorhornetq-ra

      17:52:53,103 INFO  [org.jboss.as.connector.deployment] (MSC service thread 1-1) JBAS010401: Bound JCA ConnectionFactory [java:/JmsXA]

      17:52:53,213 INFO  [org.jboss.as.ejb3] (MSC service thread 1-7) JBAS014142: Started message driven bean 'FibonacciBean' with 'hornetq-ra' resource adapter

      17:52:53,369 INFO  [org.jboss.as.server] (ServerService Thread Pool -- 32) JBAS018559: Deployed "Rechner.jar" (runtime-name : "Rechner.jar")

      17:52:53,384 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015961: Http management interface listening on http://127.0.0.1:9990/management

      17:52:53,384 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015951: Admin console listening on http://127.0.0.1:9990

      17:52:53,384 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015874: JBoss AS 7.2.0.Final "Janus" started in 4107ms - Started 194 of 255 services (60 services are passive or on-demand)

       

      In my management webgui I also see all the queus and factories.

       

      Factory.png

      And now I try to connect with a client to the Server, but he can't find the factories or queues and I have no idea on how to get the proper jndi-name.

       

      package client;
      
      import java.util.Hashtable;
      import java.util.Properties;
      import javax.jms.Connection;
      import javax.jms.ConnectionFactory;
      import javax.jms.MessageProducer;
      import javax.jms.Queue;
      import javax.jms.Session;
      import javax.jms.TextMessage;
      import javax.naming.Context;
      import javax.naming.InitialContext;
      import javax.naming.NamingException;
      import javax.rmi.PortableRemoteObject;
      import org.jboss.ejb.client.EJBClientContext;
      import org.jboss.ejb.client.PropertiesBasedEJBClientConfiguration;
      import org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector;
      
      public class Client
      {
      
        private final String factoryJNDILookup = "jms/RemoteConnectionFactory";
        private final String queueJNDILookup = "queue/FibonacciQueue";
      
        private ConnectionFactory connectionFactory;
        private Queue queue;
      
        public Client()
        {
          Properties jbossClientProps = new Properties();
          jbossClientProps.setProperty("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", "false");
          jbossClientProps.setProperty("remote.connections", "default");
          jbossClientProps.setProperty("remote.connection.default.host", "localhost");
          jbossClientProps.setProperty("remote.connection.default.port", "4447");
          jbossClientProps.setProperty("remote.connection.default.username", "user");
          jbossClientProps.setProperty("remote.connection.default.password", "pass");
          jbossClientProps.setProperty("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT", "false");
          jbossClientProps.setProperty("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS", "true");
          jbossClientProps.setProperty("remote.connection.default.connect.options.org.xnio.Options.SASL_DISALLOWED_MECHANISMS", "JBOSS-LOCAL-USER");
          PropertiesBasedEJBClientConfiguration ejbcfg = new PropertiesBasedEJBClientConfiguration(jbossClientProps);
          ConfigBasedEJBClientContextSelector ejbClientSelector = new ConfigBasedEJBClientContextSelector(ejbcfg);
          EJBClientContext.setSelector(ejbClientSelector);
      
          Hashtable<String, String> env = new Hashtable<String, String>();
          env.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
          
          try
          {
            InitialContext initialContext = new InitialContext(env);
      
            Object connectionFactoryObjectReference = initialContext.lookup(factoryJNDILookup);
            Object connectionFactoryObject = PortableRemoteObject.narrow(connectionFactoryObjectReference, ConnectionFactory.class);
            this.connectionFactory = ConnectionFactory.class.cast(connectionFactoryObject);
            
            Object queueReference = initialContext.lookup(queueJNDILookup);
            Object queueObject = PortableRemoteObject.narrow(queueReference, Queue.class);
            this.queue = Queue.class.cast(queueObject);
      
          } catch (NamingException e)
          {
            e.printStackTrace();
          }
        }
      
        public void start()
        {
          try
          {
            Connection connection = connectionFactory.createConnection();
            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            MessageProducer messageProducer = session.createProducer(queue);
            TextMessage message = session.createTextMessage();
            message.setText("This is a message, Hello");
      
            messageProducer.send(message);
      
            System.out.println("done");
          } catch (Exception e)
          {
            e.printStackTrace();
          }
        }
      
        public static void main(String args[])
        {
          Client client = new Client();
          client.start();
        }
      
      }
      
      

       

      And it all fails in Line 51 with:

       

      javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial

       

      He is unable to find either the queue nore the factory.

      Also tried it with: jboss/exported/jms/RemoteConnectionFactory ; ejb:/jboss/exported/jms/RemoteConnectionFactory!RemoteConnectionFactory ; RemoteConnectionFactory

       

      Any help would be appreciated.