HOWTO: Use MSMQ within an MTS Component in Java (176816)
The information in this article applies to:
- Microsoft Message Queue Server (MSMQ) 1.0
- Microsoft Transaction Server 1.0
- Microsoft Visual J++ 1.0
This article was previously published under Q176816 SUMMARY
This article describes how to use Microsoft Message Queue Server (MSMQ)
from within Microsoft Transaction Server (MTS) components written in Java
using Visual J++. The two MSMQ transactional operations available are the
message Send and Receive operations.
MSMQ Send operations can be included in MTS transactions. The Send
operation is either committed or rolled back with the MTS transaction. As a
result, the message is not sent until the transaction commits. To include
the Send operation in a transaction, use the MQ_MTS_TRANSACTION constant
for the Transaction parameter of the MSMQMessage.Send method from within a
transactional MTS component. MSMQ enlists the Send operation in the MTS
transaction. The destination queue must be a transactional queue.
Transactional messages can only be sent to a transactional destination
queue. If the MTS component is not participating in a transaction, the Send
operation described above fails. This happens because the message would be
non-transactional, and you cannot send a non-transactional message to a
transactional queue. You cannot always predict whether a component will
participate in a transaction. Therefore, it is important to verify that the
component is participating in the transaction and use MQ_MTS_TRANSACTION in
the MSMQMessage.Send to a transactional queue only if the component is
participating. If it is not participating, use the MQ_NO_TRANSACTION to
send to a non-transactional queue or MQ_SINGLE_MESSAGE constant to send to
a transactional queue.
The component is participating in the transaction if it is marked as
"Requires [new] Transactions" or "Supports Transactions" in MTS Explorer.
The component is not participating in the transaction if it is marked as
"Does Not Support Transactions."
When the MTS component is marked as "Supports Transaction," it participates
in a transaction if its caller participates. For sending from such a
component, you must dynamically check for the current transaction existence
(use the ObjectContext.IsInTransaction method) and use an appropriate
Transaction flag and destination queue.
For a local MSMQ transactional queue, the receive operation specifying
MQ_MTS_TRANSACTION works regardless of whether or not the component is
transactional. The receive operation is only included in a transaction if
the component is transactional.
REFERENCES
For more information on creating an MTS COM component from your Java class,
please see the documentation that comes with Microsoft Visual J++ and
Microsoft Transaction Server.
For more details on using a single queue for Send/Receive and to avoid
queue and component type mismatch, see the following Knowledge Base
article:
174387 INFO: Using a Single MSMQ Queue for an MTS Component
Modification Type: | Minor | Last Reviewed: | 3/11/2005 |
---|
Keywords: | kbcode kbhowto kbJava KB176816 |
---|
|