使用 Java API 显式提交或回滚 MQ 工作单元
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15208973/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Explicitly commit or rollback an MQ unit of work using Java APIs
提问by Paul H
I'm working on a standalone Java application that GETs several messages from one MQ queue, processes the data contained within the messages and then PUTs a new message onto another MQ queue. One of the requirements is for the GET and PUT operations to be within the same unit of work and I am able to do this by specifying MQGMO_SYNCPOINT
and MQGMO_SYNCPOINT
get/put message options.
我正在开发一个独立的 Java 应用程序,该应用程序从一个 MQ 队列中获取多条消息,处理消息中包含的数据,然后将一条新消息放入另一个 MQ 队列。要求之一是 GET 和 PUT 操作在同一个工作单元中,我可以通过指定MQGMO_SYNCPOINT
和MQGMO_SYNCPOINT
获取/放置消息选项来做到这一点。
What I don't understand how to do using the Java MQ API is perform the MQCMIT and MQBACK operations to explicitly commit or rollback the MQ unit of work.
我不明白如何使用 Java MQ API 执行 MQCMIT 和 MQBACK 操作以显式提交或回滚 MQ 工作单元。
I've searched on the IBM MQ InfoCenter website and the JavaDoc but I can't find anything on the APIs used for committing and rolling back a unit of work.
我在 IBM MQ InfoCenter 网站和 JavaDoc 上进行了搜索,但在用于提交和回滚工作单元的 API 上找不到任何内容。
The version of WebSphere MQ I'm using is 7.5 and I'm connecting to the queue manager using binding mode.
我使用的 WebSphere MQ 版本是 7.5,我使用绑定模式连接到队列管理器。
Would anyone be able to provide some example code showing how to explicitly commit or rollback the MQ unit of work using the Java MQ APIs or point me in the direction of the appropriate JavaDoc page please?
任何人都可以提供一些示例代码,显示如何使用 Java MQ API 显式提交或回滚 MQ 工作单元,或者请指出我正确的 JavaDoc 页面的方向?
回答by ahjmorton
The basic flow is that when you send the messages in a transaction it will hold the messages in a buffer until either a commit or rollback is called: if a commit is performed then the messages are sent, otherwise they are discarded.
基本流程是,当您在事务中发送消息时,它会将消息保存在缓冲区中,直到调用提交或回滚:如果执行提交,则发送消息,否则将丢弃它们。
Below is a sample from Novell using the JMS APIs which should be the same as WebSphere MQ if you're using the JMS API :
下面是来自 Novell 的使用 JMS API 的示例,如果您使用 JMS API,它应该与 WebSphere MQ 相同:
http://www.novell.com/documentation/extend52/Docs/help/MP/jms/tutorial/txSession-1.htm
http://www.novell.com/documentation/extend52/Docs/help/MP/jms/tutorial/txSession-1.htm
UPDATE :Below is another question on StackOverflow that has code for committing / rolling back using the Websphere MQ APIs :
更新:以下是 StackOverflow 上的另一个问题,其中包含使用 Websphere MQ API 提交/回滚的代码: