First go to the following location: <jboss home>/server/default/deploy/messaging
then open the connection-factories-service.xml in your favorite editor and if you did not change anything there you should probably have the following JNDI binding details
<attribute name="JNDIBindings">
<bindings>
<binding>/ConnectionFactory</binding>
<binding>/XAConnectionFactory</binding>
<binding>java:/ConnectionFactory</binding>
<binding>java:/XAConnectionFactory</binding>
</bindings>
</attribute>
If it's anything other than that note down the connection factory you have. Then go to destinations-service.xml and make sure you have configured queues correctly and note down the JNDIName of queue you want to connect (For this example we'll say it's queue/testQueue).
Thinking all these are configured correctly lets move on to the client code. First you will least need following libraries (You can find all these jar files inside jboss lib folder)
- concurrent.jar
- javassist.jar
- jbossall-client5.jar
- log4j-boot.jar
- trove.jar
Following imports will be used in your code,
import javax.jms.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import java.util.Hashtable;
Following is the code to connect to a jboss jms queue
Hashtable props = new Hashtable();
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
props.put(Context.PROVIDER_URL, "jnp://127.0.0.1:1099"); //Add your correct ip and port if anything other than this
props.put("java.naming.rmi.security.manager", "yes");
props.put(Context.URL_PKG_PREFIXES, "org.jboss.naming");
Context context = new InitialContext(props);
QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory) context.lookup("ConnectionFactory");//Your connection factory if anything other than this
Queue myOutputQueue = (Queue) context.lookup("queue/testQueue");//Your queue name goes here
QueueConnection queueConnection = queueConnectionFactory.createQueueConnection();
QueueSession queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
QueueSender queueSender = queueSession.createSender(myOutputQueue);
queueConnection.start();
TextMessage sendmsg = queueSession.createTextMessage();
sendmsg.setJMSExpiration(600);
sendmsg.setText("Testing message");
queueSender.send(sendmsg);
queueConnection.stop();
With this you should be able to connect and write a text message to jboss jms queues.