title: Write a Java Program to connect to HornetQ Messaging Service in Jboss EAP 6.3?
body: <p>I am using Jboss EAP 6.3 and need to use Messaging facility. 
  I have worked in Jboss 4x, where we can make connection easily using following code:</p>
  
  <pre><code>public static final String PROVIDER_URL = "jnp://localhost:5445";
     public static final String JNP_INTERFACES = "org.jboss.naming:org.jnp.interfaces";
     public static final String INITIAL_CONTEXT_FACTORY = "org.jnp.interfaces.NamingContextFactory";
  
     private static Context initialContext;
  
     public static Context getInitialContextForClient() throws NamingException{
            if(initialContext == null){
                   Properties prop = new Properties();
                   prop.put(Context.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT_FACTORY);
                   prop.put(Context.URL_PKG_PREFIXES,JNP_INTERFACES);
                   prop.put(Context.PROVIDER_URL, PROVIDER_URL);
                   initialContext = new InitialContext(prop);
            }
            return initialContext;
     }
  </code></pre>
  
  <p>Will above way work in EAP 6.3 to connect to HornetQ? If yes, what other configurations are required? Also, i found 1099 is also not configured by default in standalone.xml.</p>
  
  <p>Following are by default settings done for HornetQ in Standalone-full.xml file:</p>
  
  <pre><code>&lt;subsystem xmlns="urn:jboss:domain:messaging:1.4"&gt;
          &lt;hornetq-server&gt;
              &lt;persistence-enabled&gt;true&lt;/persistence-enabled&gt;
              &lt;journal-type&gt;NIO&lt;/journal-type&gt;
              &lt;journal-min-files&gt;2&lt;/journal-min-files&gt;
  
              &lt;connectors&gt;
                  &lt;netty-connector name="netty" socket-binding="messaging"/&gt;
                  &lt;netty-connector name="netty-throughput" socket-binding="messaging-throughput"&gt;
                      &lt;param key="batch-delay" value="50"/&gt;
                  &lt;/netty-connector&gt;
                  &lt;in-vm-connector name="in-vm" server-id="0"/&gt;
              &lt;/connectors&gt;
  
              &lt;acceptors&gt;
                  &lt;netty-acceptor name="netty" socket-binding="messaging"/&gt;
                  &lt;netty-acceptor name="netty-throughput" socket-binding="messaging-throughput"&gt;
                      &lt;param key="batch-delay" value="50"/&gt;
                      &lt;param key="direct-deliver" value="false"/&gt;
                  &lt;/netty-acceptor&gt;
                  &lt;in-vm-acceptor name="in-vm" server-id="0"/&gt;
              &lt;/acceptors&gt;
  
              &lt;security-settings&gt;
                  &lt;security-setting match="#"&gt;
                      &lt;permission type="send" roles="guest"/&gt;
                      &lt;permission type="consume" roles="guest"/&gt;
                      &lt;permission type="createNonDurableQueue" roles="guest"/&gt;
                      &lt;permission type="deleteNonDurableQueue" roles="guest"/&gt;
                  &lt;/security-setting&gt;
              &lt;/security-settings&gt;
  
              &lt;address-settings&gt;
                  &lt;address-setting match="#"&gt;
                      &lt;dead-letter-address&gt;jms.queue.DLQ&lt;/dead-letter-address&gt;
                      &lt;expiry-address&gt;jms.queue.ExpiryQueue&lt;/expiry-address&gt;
                      &lt;redelivery-delay&gt;0&lt;/redelivery-delay&gt;
                      &lt;max-size-bytes&gt;10485760&lt;/max-size-bytes&gt;
                      &lt;page-size-bytes&gt;2097152&lt;/page-size-bytes&gt;
                      &lt;address-full-policy&gt;PAGE&lt;/address-full-policy&gt;
                      &lt;message-counter-history-day-limit&gt;10&lt;/message-counter-history-day-limit&gt;
                  &lt;/address-setting&gt;
              &lt;/address-settings&gt;
  
              &lt;jms-connection-factories&gt;
                  &lt;connection-factory name="InVmConnectionFactory"&gt;
                      &lt;connectors&gt;
                          &lt;connector-ref connector-name="in-vm"/&gt;
                      &lt;/connectors&gt;
                      &lt;entries&gt;
                          &lt;entry name="java:/ConnectionFactory"/&gt;
                      &lt;/entries&gt;
                  &lt;/connection-factory&gt;
                  &lt;connection-factory name="RemoteConnectionFactory"&gt;
                      &lt;connectors&gt;
                          &lt;connector-ref connector-name="netty"/&gt;
                      &lt;/connectors&gt;
                      &lt;entries&gt;
                          &lt;entry name="java:jboss/exported/jms/RemoteConnectionFactory"/&gt;
                      &lt;/entries&gt;
                  &lt;/connection-factory&gt;
                  &lt;pooled-connection-factory name="hornetq-ra"&gt;
                      &lt;transaction mode="xa"/&gt;
                      &lt;connectors&gt;
                          &lt;connector-ref connector-name="in-vm"/&gt;
                      &lt;/connectors&gt;
                      &lt;entries&gt;
                          &lt;entry name="java:/JmsXA"/&gt;
                      &lt;/entries&gt;
                  &lt;/pooled-connection-factory&gt;
              &lt;/jms-connection-factories&gt;
  
              &lt;jms-destinations&gt;
                  &lt;jms-queue name="ExpiryQueue"&gt;
                      &lt;entry name="java:/jms/queue/ExpiryQueue"/&gt;
                  &lt;/jms-queue&gt;
                  &lt;jms-queue name="DLQ"&gt;
                      &lt;entry name="java:/jms/queue/DLQ"/&gt;
                  &lt;/jms-queue&gt;
              &lt;/jms-destinations&gt;
          &lt;/hornetq-server&gt;
      &lt;/subsystem&gt;
  </code></pre>
  
  <p>Following are socket bindings in same file:</p>
  
  <pre><code>&lt;socket-binding name="messaging" port="5445"/&gt;
      &lt;socket-binding name="messaging-group" port="0" multicast-address="${jboss.messaging.group.address:231.7.7.7}" multicast-port="${jboss.messaging.group.port:9876}"/&gt;
      &lt;socket-binding name="messaging-throughput" port="5455"/&gt;
  </code></pre>
  
  <p>I tried it like below because unable to see org.jnp.interfaces.NamingContextFactory class in Jboss EAP 6.3: </p>
  
  <pre><code>prop.put(Context.PROVIDER_URL,"localhost:5445"); 
  prop.put(Context.INITIAL_CONTEXT_FACTORY,"org.hornetq.core.remoting.impl.netty.NettyConnectorFactory");
  prop.put(Context.URL_PKG_PREFIXES,"org.jboss.naming:org.jnp.interfaces");
  </code></pre>
  
  <p>Currently, it is throwing Connection Exception. </p>
  
  <p>Could anyone please suggest or submit a java program on how to achieve connection with Hornetq in Jboss EAP 6.3?</p>
  
  <p><strong>Update</strong>:
  I still do not know whether i am following correct procedure of doing the same. </p>
  
  <p>Following is exceptions which i am getting:</p>
  
  <pre><code>javax.naming.NamingException: JBAS011843: Failed instantiate InitialContextFactory org.jnp.interfaces.NamingContextFactory from classloader ModuleClassLoader for Module 
  </code></pre>
  
  <p>I have checked its jboss-client.jar in bin/client and found the above interface is not present there but is present in previous versions which contains jbiss-allclient.jar. I do not think putting that in this jboss version is correct to do.</p>