An application sends messages using a MessageProducer object. A MessageProducer object is normally created for a specific destination so that all messages sent using that message producer are sent to the same destination. The destination is specified using either a Queue or a Topic object. Queue and Topic objects can be created at runtime, or built and stored in a JNDI namespace, as described in Destinations.
After a Queue or a Topic object is obtained, an application can pass the object to the createProducer() method to create a MessageProducer object, as shown in the following example:
MessageProducer messageProducer = session.createProducer(ioDestination);
The parameter ioDestination can be either a Queue or a Topic object.
The application can then use the send() method on the MessageProducer object to send messages. Here is an example:
messageProducer.send(outMessage);
You can use the send() method to send messages in either messaging domain. The nature of the destination determines the actual domain used. However, TopicPublisher, the sub-interface for MessageProducer that is specific to the publish/subscribe domain, uses a publish() method instead.
An application can create a MessageProducer object with no specified destination. In this case, the application must specify the destination in the send() method.
JMS provides several message types, each of which embodies some knowledge of its content. To avoid referring to the provider specific class names for the message types, methods for creating messages are provided on a Session object.
For example, a text message can be created in the following manner:
System.out.println( "Creating a TextMessage" ); TextMessage outMessage = session.createTextMessage(); System.out.println("Adding Text"); outMessage.setText(outString);
Here are the message types you can use:
Details of these types are in WebSphere MQ JMS API reference.
Notices |
Downloads |
Library |
Support |
Feedback
![]() ![]() |
jms11sdm |