Messages are sent using a MessageProducer. For point-to-point this is a QueueSender that is created using the createSender() method on QueueSession. A QueueSender is normally created for a specific Queue, so that all messages sent using that sender are sent to the same destination. Queue objects can be either created at runtime, or built and stored in a JNDI namespace. Refer to Using Java Naming and Directory Interface (JNDI), for details on how to store and retrieve objects using JNDI.
JMS provides a mechanism to create a Queue at runtime that minimizes the implementation-specific code in the application. This mechanism uses the QueueSession.createQueue() method, which takes a string parameter describing the destination. The string itself is still in an implementation-specific format, but this is a more flexible approach than directly referencing the implementation classes.
ioQueue = session.createQueue("myQM+myQueue");This will create a JMS Queue representing the MQe queue "myQueue" on queue manager "myQM". If no queue manager name is specified the local queue manager is used, i.e. the one that JMS is connected to. For example:
String queueName = "SYSTEM.DEFAULT.LOCAL.QUEUE"; ... ioQueue = session.createQueue(queueName);This will create a JMS Queue representing the MQe queue SYSTEM.DEFAULT.LOCAL.QUEUE on the queue manager that the JMS Connection is using.
System.out.println("Creating a TextMessage"); TextMessage outMessage = session.createTextMessage(); System.out.println("Adding Text"); outMessage.setText(outString);