Java Reference
In-Depth Information
producer.send(outQueue, outMsg);
consumer = session.createConsumer(replyQueue);
inMsg = consumer.receive(); session.commit();
Because a message sent during a transaction is not actually sent until the transaction is
committed, the transaction cannot contain any receives that depend on that message's hav-
ing been sent.
In addition, the production and the consumption of a message cannot both be part of the
same transaction. The reason is that the transactions take place between the clients and the
JMS provider, which intervenes between the production and the consumption of the mes-
sage. Figure 20-8 illustrates this interaction.
FIGURE 20-8. Using JMS API Local Transactions
The sending of one or more messages to one or more destinations by Client 1 can form
a single transaction, because it forms a single set of interactions with the JMS provider
using a single session. Similarly, the receiving of one or more messages from one or more
destinations by Client 2 also forms a single transaction using a single session. But because
the two clients have no direct interaction and are using two different sessions, no transac-
tions can take place between them.
Another way of putting this is that the act of producing and/or consuming messages in a
session can be transactional, but the act of producing and consuming a specific message
across different sessions cannot be transactional.
This is the fundamental difference between messaging and synchronized processing. In-
stead of tightly coupling the sending and receiving of data, message producers and con-
sumers use an alternative approach to reliability, built on a JMS provider's ability to sup-
ply a once-and-only-once message delivery guarantee.
When you create a session, you specify whether it is transacted. The first argument to
the createSession method is a boolean value. A value of true means the session
is transacted; a value of false means it is not transacted. The second argument to this
method is the acknowledgment mode, which is relevant only to nontransacted sessions
(see “ Controlling Message Acknowledgment ” on page 360 ). If the session is transacted,
Search WWH ::




Custom Search