1 Reply Latest reply on Oct 7, 2014 10:57 AM by Justin Bertram

    Remote JNDI hornetQ queues access problem

    Michael Jordan Newbie

      Hi,

      I'm working on standalone client which is gonna register as listener to some queue configured within Wildfly 8.1.0 AS. Here's configuration of hornetQ:

      <hornetq-server>

                      <persistence-enabled>true</persistence-enabled>

                      <security-enabled>false</security-enabled>

                      <journal-file-size>102400</journal-file-size>

                      <journal-min-files>2</journal-min-files>

                      <connectors>

                          <http-connector name="http-connector" socket-binding="http">

                              <param key="http-upgrade-endpoint" value="http-acceptor"/>

                          </http-connector>

                          <http-connector name="http-connector-throughput" socket-binding="http">

                              <param key="http-upgrade-endpoint" value="http-acceptor-throughput"/>

                              <param key="batch-delay" value="50"/>

                          </http-connector>

                          <in-vm-connector name="in-vm" server-id="0"/>

                      </connectors>

                      <acceptors>

                          <http-acceptor http-listener="default" name="http-acceptor"/>

                          <http-acceptor http-listener="default" name="http-acceptor-throughput">

                              <param key="batch-delay" value="50"/>

                              <param key="direct-deliver" value="false"/>

                          </http-acceptor>

                          <in-vm-acceptor name="in-vm" server-id="0"/>

                          <acceptor name="netty">

                              <factory-class>org.hornetq.core.remoting.impl.netty.NettyAcceptorFactory</factory-class>

                              <param key="host" value="0.0.0.0"/>

                              <param key="port" value="5446"/>

                          </acceptor>

                      </acceptors>

                      <security-settings>

                          <security-setting match="#">

                              <permission type="send" roles="guest"/>

                              <permission type="consume" roles="guest"/>

                              <permission type="createDurableQueue" roles="guest"/>

                              <permission type="deleteDurableQueue" roles="guest"/>

                              <permission type="createNonDurableQueue" roles="guest"/>

                              <permission type="deleteNonDurableQueue" roles="guest"/>

                          </security-setting>

                      </security-settings>

                      <address-settings>

                          <address-setting match="#">

                              <dead-letter-address>jms.queue.DLQ</dead-letter-address>

                              <max-size-bytes>10485760</max-size-bytes>

                              <page-size-bytes>2097152</page-size-bytes>

                              <message-counter-history-day-limit>10</message-counter-history-day-limit>

                          </address-setting>

                      </address-settings>

                      <jms-connection-factories>

                          <connection-factory name="InVmConnectionFactory">

                              <connectors>

                                  <connector-ref connector-name="in-vm"/>

                              </connectors>

                              <entries>

                                  <entry name="java:/ConnectionFactory"/>

                              </entries>

                          </connection-factory>

                          <connection-factory name="RemoteConnectionFactory">

                              <connectors>

                                  <connector-ref connector-name="http-connector"/>

                              </connectors>

                              <entries>

                                  <entry name="java:jboss/exported/jms/cr/RemoteConnectionFactory"/>

                              </entries>

                          </connection-factory>

                          <pooled-connection-factory name="hornetq-ra">

                              <transaction mode="xa"/>

                              <connectors>

                                  <connector-ref connector-name="in-vm"/>

                              </connectors>

                              <entries>

                                  <entry name="java:/JmsXA"/>

                                  <entry name="java:jboss/DefaultJMSConnectionFactory"/>

                              </entries>

                          </pooled-connection-factory>

                      </jms-connection-factories>

                      <jms-destinations>

                          <jms-queue name="DispatcherToReceptionCenterQueue">

                              <entry name="jms/queue/DispatcherToCRQueue"/>

                              <entry name="java:jboss/exported/jms/queue/DispatcherToCRQueue"/>

                          </jms-queue>

                          <jms-queue name="ReceptionCenterToControlCenterQueue">

                              <entry name="jms/queue/CRToCCQueue"/>

                              <entry name="java:jboss/exported/jms/queue/CRToCCQueue"/>

                          </jms-queue>

                          <jms-queue name="AlarmClientsToReceptionCenterQueue">

                              <entry name="jms/queue/AlarmClientsToCRQueue"/>

                              <entry name="java:jboss/exported/jms/queue/AlarmClientsToCRQueue"/>

                          </jms-queue>

                          <jms-topic name="ReceptionCenterToAlarmClientsTopic">

                              <entry name="jms/topic/CRToAlarmClientsTopic"/>

                              <entry name="java:jboss/exported/jms/topic/CRToAlarmClientsTopic"/>

                          </jms-topic>

                      </jms-destinations>

      </hornetq-server>

       

      Here is my client's code:

       

          private static final String DEFAULT_CONNECTION_FACTORY = "jms/cr/RemoteConnectionFactory";

          private static final String DESTINATION_TO_CR = "jms/queue/AlarmClientsToCRQueue";

          private static final String SOURCE_FROM_CR = "jms/topic/CRToAlarmClientsTopic";

          private static final String DEFAULT_MESSAGE_COUNT = "100";

          private static final String INITIAL_CONTEXT_FACTORY = "org.jboss.naming.remote.client.InitialContextFactory";

          private static final String PROVIDER_URL = "http-remoting://10.168.56.100:8080";

       

      final Properties env = new Properties();

                      env.put(Context.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT_FACTORY);

                      env.put("jboss.naming.client.ejb.context", true);

                      env.put(Context.PROVIDER_URL, System.getProperty(Context.PROVIDER_URL, PROVIDER_URL));

                      env.put(Context.SECURITY_AUTHENTICATION, "none");

                      namingContext = new InitialContext(env);

       

                      // Perform the JNDI lookups

                      String connectionFactoryString = System.getProperty("connection.factory", DEFAULT_CONNECTION_FACTORY);

                      System.out.println("Attempting to acquire connection factory \"" + connectionFactoryString + "\"");

                      ConnectionFactory connectionFactory = (ConnectionFactory) namingContext.lookup(connectionFactoryString);

                      System.out.println("Found connection factory \"" + connectionFactory + "\" in JNDI");

       

                      String destinationString = System.getProperty("destination", DESTINATION_TO_CR);

                      String sourceString = System.getProperty("destination", SOURCE_FROM_CR);

       

                      System.out.println("Attempting to acquire destination \"" + destinationString + "\"");

                      Destination destination = (Destination) namingContext.lookup(destinationString);

                      System.out.println("Found destination \"" + destination + "\" in JNDI");

       

                      System.out.println("Attempting to acquire topic \"" + sourceString + "\"");

                      Topic source = (Topic) namingContext.lookup(sourceString);

                      System.out.println("Found topic \"" + source + "\" in JNDI");

       

                      int count = Integer.parseInt(System.getProperty("message.count", DEFAULT_MESSAGE_COUNT));

                      String content = System.getProperty("message.content", DEFAULT_MESSAGE);

       

                      try {

                          consumer = connectionFactory.createConnection().createSession(false, Session.AUTO_ACKNOWLEDGE).createConsumer(source);

                         System.out.println("created consumer");

                          consumer.setMessageListener(helloWorldJMSClient);

                      } catch (Exception e) {

                          e.printStackTrace();

                      }

       

       

      I'm getting Exception as follows:

      javax.jms.JMSException: Failed to create session factory

              at org.hornetq.jms.client.HornetQConnectionFactory.createConnectionInternal(HornetQConnectionFactory.java:673)

              at org.hornetq.jms.client.HornetQConnectionFactory.createConnection(HornetQConnectionFactory.java:112)

              at org.hornetq.jms.client.HornetQConnectionFactory.createConnection(HornetQConnectionFactory.java:107)

              at gmv.greenboxes.alarm.client.HelloWorldJMSClient.lambda$main$0(HelloWorldJMSClient.java:86)

              at gmv.greenboxes.alarm.client.HelloWorldJMSClient$$Lambda$1/523429237.run(Unknown Source)

              at java.lang.Thread.run(Thread.java:745)

      Caused by: HornetQNotConnectedException[errorType=NOT_CONNECTED message=HQ119007: Cannot connect to server(s). Tried with all available servers.]

              at org.hornetq.core.client.impl.ServerLocatorImpl.createSessionFactory(ServerLocatorImpl.java:905)

              at org.hornetq.jms.client.HornetQConnectionFactory.createConnectionInternal(HornetQConnectionFactory.java:669)

       

      Can anyone help me with this problem ?