8

I'm writing a simple Java application using MQ classes for Java with Eclipse.

Right now I'm able to browse a remote queue without removing the messages stored.
Here is the code of the reading cycle:

MQQueueManager QMgr = new MQQueueManager(qManager); //<-- qManager is a String with the QMgr name

int openOptions = MQC.MQOO_FAIL_IF_QUIESCING | MQC.MQOO_INPUT_SHARED | MQC.MQOO_BROWSE;  

MQQueue queue = QMgr.accessQueue(queueName, openOptions);

MQMessage theMessage    = new MQMessage();
MQGetMessageOptions gmo = new MQGetMessageOptions();
    gmo.options=MQC.MQGMO_WAIT | MQC.MQGMO_BROWSE_FIRST;
    gmo.matchOptions=MQC.MQMO_NONE;
    gmo.waitInterval=5000;

boolean thereAreMessages=true;
while(thereAreMessages){
    try{
        //read the message          
        queue.get(theMessage,gmo);  
        //print the text            
        String msgText = theMessage.readString(theMessage.getMessageLength());
        System.out.println("msg text: "+msgText);

                 // <--- Solution code Here

        //move cursor to the next message               
        gmo.options = MQC.MQGMO_WAIT | MQC.MQGMO_BROWSE_NEXT;

    }catch(MQException e){

        if(e.reasonCode == e.MQRC_NO_MSG_AVAILABLE) {
            System.out.println("no more message available or retrived");
        }

        thereAreMessages=false;
    } catch (IOException e) {
        System.out.println("ERROR: "+e.getMessage());
    }
}

Main question: After the read message line and before moving the cursor to the next message how can I remove the message from the queue?

Secondary question: Eclispe is warning me that all the costants used for the options are deprecated; which are the correct ones to use?


Solution:

Here the solution I'm really looking for:

// set te cursor to remove the message from the queue
gmo.options = CMQC.MQGMO_MSG_UNDER_CURSOR;
queue.get(theMessage, gmo);

these lines have to be inserted in the question code

I've found it here: http://www.velocityreviews.com/forums/t124676-mq-series-messages-browse-and-delete.html

JoshMc
  • 10,239
  • 2
  • 19
  • 38
Mave751
  • 697
  • 4
  • 11
  • 25
  • 1
    I'm sorry for this mistake, now my question (and other two before) should be more compliant. I'm new and I'm learning how to use this platform day by day. I'm going to mark the answer to close it as soon as I will be allowed. – Mave751 Sep 03 '12 at 06:17
  • How to clear in single command ? I have 1000 messages in my Queue and this steps not super fast for huge messages. – Shankar Oct 07 '20 at 10:56

2 Answers2

10

Solution:

Here the solution I'm really looking for:

// set te cursor to remove the message from the queue
gmo.options = CMQC.MQGMO_MSG_UNDER_CURSOR;
queue.get(theMessage, gmo);

these lines have to be inserted in the question code

I've found it here: http://www.velocityreviews.com/forums/t124676-mq-series-messages-browse-and-delete.html

Mave751
  • 697
  • 4
  • 11
  • 25
  • Basically same worked for me in the .NET C# interface: MQGetMessageOptions mqGetMessageOptionsDel = new MQGetMessageOptions(); mqGetMessageOptions.Options = MQC.MQGMO_MSG_UNDER_CURSOR; queueIn.Get(mqMessage, mqGetMessageOptionsDel); – NealWalters Feb 27 '13 at 23:26
  • How to Clear for 1000 messages – Shankar Oct 07 '20 at 10:57
-1

To delete a message, follow the procedure described in the MQ documentation.

For deprecated constant values, check again the Javadoc, the recommended way is described.

MQC.MQOO_INPUT_SHARED --> CMQC.MQOO_INPUT_SHARED
RealHowTo
  • 34,977
  • 11
  • 70
  • 85