Java Reference
In-Depth Information
Session session = connection.createSession(true, 0);
Here, the first argument means the session is transacted; the second indicates that message
acknowledgment is not specified for transacted sessions. For more information on trans-
actions, see “ Using JMS API Local Transactions ” on page 366 . For information about the
way JMS transactions work in Java EE applications, see “ Using the JMS API in Java EE
Applications on page 368 .
JMS Message Producers
A message producer is an object that is created by a session and used for sending mes-
sages to a destination. It implements the MessageProducer interface.
You use a Session to create a MessageProducer for a destination. The following
examples show that you can create a producer for a Destination object, a Queue ob-
ject, or a Topic object.
Click here to view code image
MessageProducer producer = session.createProducer(dest);
MessageProducer producer = session.createProducer(queue);
MessageProducer producer = session.createProducer(topic);
You can create an unidentified producer by specifying null as the argument to cre-
ateProducer . With an unidentified producer, you do not specify a destination until you
send a message.
After you have created a message producer, you can use it to send messages by using the
send method:
producer.send(message);
You must first create the messages; see “ JMS Messages ” on page 355 .
If you have created an unidentified producer, use an overloaded send method that speci-
fies the destination as the first parameter. For example:
Click here to view code image
MessageProducer anon_prod = session.createProducer(null);
anon_prod.send(dest, message);
JMS Message Consumers
A message consumer is an object that is created by a session and used for receiving mes-
sages sent to a destination. It implements the MessageConsumer interface.
Search WWH ::




Custom Search