简体   繁体   English

如何停止在MQ上丢失消息

[英]How do I stop losing messages on MQ

I am writing a Java application, running in a LINUX environment, that does transactions on an MQ using SYNCPOINT. 我正在编写一个在LINUX环境中运行的Java应用程序,它使用SYNCPOINT在MQ上执行事务。 It uses Websphere MQ Java Classes to interact with the MQ service. 它使用Websphere MQ Java类与MQ服务进行交互。 What I am doing in my code is the following (pseudo): 我在我的代码中做的是以下(伪):

MQGetMessageOptions gmo = new MQGetMessageOptions();
gmo.options = MQConstants.MQGMO_FAIL_IF_QUIESCING | MQConstants.MQGMO_SYNCPOINT;

MQMessage message = new Message();
queue.get(message, gmo);

// process the message, save to database

databaseConnection.commit();
queueManager.commit();

I basically grab the message, process it, persist to database, then call a commit on the queueManager. 我基本上抓取消息,处理它,持久化到数据库,然后调用queueManager上的提交。 The process listens for a message on TIBRV in order to do a graceful shutdown. 该进程在TIBRV上侦听消息,以便正常关闭。

I've been testing the process to make sure no messages are lost. 我一直在测试这个过程,以确保没有消息丢失。 I place 20k messages on a queue, then run the process. 我将20k消息放在队列中,然后运行该过程。 I perform a graceful shutdown call in the middle of processing. 我在处理过程中执行正常的关机调用。 I then compare the amount of messages on the queue versus the amount of messages in database. 然后,我比较队列中的消息量与数据库中的消息量。 When a graceful shutdown occurs via TIBRV message, the number of MQ messages + the number of DB messages = total messages originally on the queue. 通过TIBRV消息进行正常关闭时,MQ消息数+ DB消息数=最初在队列中的消息总数。

However, when I do a kill or kill -9 , I see that a message is lost. 但是,当我执行killkill -9 ,我发现消息丢失了。 I always end up with a result of 19999 total messages. 我总是得到19999总消息的结果。

Is there a way I can investigate how I am losing this message? 有没有办法可以调查我如何丢失这条消息? Is there anything that occurs on the Websphere App Server that I would need to be aware of? Websphere App Server上是否有任何我需要注意的事项?

There is no reason to expect the numbers to reconcile when using single-phase commit. 在使用单阶段提交时,没有理由期望数字能够协调。 The program will always be between the WMQ and DB Commit call or else between the DB and WMQ Commit call when you kill it. 程序将始终在WMQ和数据库提交调用之间,或者在您杀死它时在数据库和WMQ提交调用之间。

What you are asking for would require 2-Phase (XA) Commit. 您要求的是需要两阶段(XA)提交。 For WMQ, 2PC would require the application to be using bindings mode and for WMQ to be the resource coordinator. 对于WMQ,2PC将要求应用程序使用绑定模式,并且要求WMQ成为资源协调器。 You would then call MQBEGIN, execute your WMQ and DB updates, then call MQCOMMIT. 然后,您将调用MQBEGIN,执行WMQ和DB更新,然后调用MQCOMMIT。 This way both the WMQ and DB transactions would succeed or fail together. 这样,WMQ和DB事务一起成功或失败。

Are you connecting or MQ in bindings mode or client mode? 您是在绑定模式还是客户端模式下连接或MQ? In my experience, transactions didn't work out of the box in client mode, but they did in bindings mode. 根据我的经验,在客户端模式下,事务不是开箱即用的,但它们在绑定模式下完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM