Delete top message from MQQueue

I am creating a messaging system using MQSeries. For some reason, when I execute q.get (...), I get an exception (I don't know the specific MQException). The following is the code that causes the error:

private static MQGetMessageOptions GMO = new MQGetMessageOptions(); private static int GMO_OPTIONS = MQC.MQGMO_SYNCPOINT | MQC.MQGMO_WAIT; GMO.options = GMO.options | GMO_OPTIONS; GMO.waitInterval = MQC.MQWI_UNLIMITED; MQEnvironment.hostname = args[0]; MQEnvironment.channel = args[2]; MQEnvironment.port = Integer.parseInt(args[1]); MQQueueManager queueManager = new MQQueueManager(args[3]) MQMessage msg = new MQMessage(); MQQueue q = queueManager.accessQueue("qName1",MQC.MQOO_OUTPUT); q.get(msg, GMO); 

My plan is that if this error occurs, skip the message and delete it. To perform the uninstall, I will call the following function:

 private void deleteMsg(MQQueueManager queueManager, String queueName) throws MQException { MQGetMessageOptions tempGmo = new MQGetMessageOptions(); tempGmo.options |= MQC.MQGMO_WAIT; tempGmo.waitInterval = 1000; MQQueue remover = queueManager.accessQueue(queueName, MQC.MQOO_INPUT_AS_Q_DEF); remover.get(new MQMessage(), tempGmo); queueManager.commit(); } 

Will the remover.get () function in my deleteMsg function also in this particular scenario not for the same reason? Or does the parameter used to build the MQQueue (MQC.MQOO_INPUT_AS_Q_DEF vs MQC.MQOO_OUTPUT) also prevent it from crashing? If I have problems accessing my queue message, how do I delete the top message and move on to the next?

To shorten my question: If I cannot get () in the given queue to receive a message, how can we delete this damaged message in one queue?

Thanks!

+4
source share
3 answers

OMG!

 MQQueue q = queueManager.accessQueue("qName1",MQC.MQOO_OUTPUT); q.get(msg, GMO); 

You open a queue for output (recording), but try to receive a message. You have shoes on the wrong feet! Secondly, why don't you catch an MQException that MQ will throw? The exception will include a reason code that would give you an accurate explanation of your problem.

Here you should open the queue for reading:

 try { int oo = MQC.MQOO_INPUT_SHARED + MQC.MQOO_FAIL_IF_QUIESCING; MQQueue q = queueManager.accessQueue("qName1",oo); MQGetMessageOptions gmo = new MQGetMessageOptions(); gmo.options = MQC.MQGMO_NO_WAIT + MQC.MQGMO_FAIL_IF_QUIESCING; q.get(msg, gmo); } catch (MQException e) { System.err.println(e.getLocalizedMessage() ); System.err.println("CC = " + e.completionCode + " - RC = " + e.reasonCode); } 

Also, make sure you use the appropriate โ€œFail if quiescingโ€ option for a specific MQ API call.

Finally, find the "backup queue". If your application has a problem with the message, the message should be transferred to the backup queue, and not just deleted.

+4
source

I donโ€™t understand why what you are doing is not working for you, but I wonder why you are using the MQ Series proprietary API instead of using the JMS API. In JMS terms, deleting the top message simply means receiving the message, so calling session.receieve() does the job.

Using the regular JMS API has many advantages. The main one is that you can easily switch from the MQ series to any other messaging solution without even changing one line of your code.

0
source

I wonder if the program compiled because there is no option called GMO_OPTIONS. All MQ constants are prefixed with MQC

0
source

Source: https://habr.com/ru/post/1483624/


All Articles