MQ

 View Only
  • 1.  Websphere MQ filter Support for more fields

    Posted Mon March 20, 2023 09:23 AM

    Team,

    with java code, we are reading Queue messages, and also reading with filter.

    We are using the below function to read queue messages with a filter. this function supports only 6 fields but Queue has more than 25 fields

    1) gmo.matchOptions =
    MQConstants.MQMO_MATCH_MSG_SEQ_NUMBER;

    2) gmo.matchOptions = MQConstants.MQMO_MATCH_GROUP_ID;

    3) gmo.matchOptions =
    MQConstants.MQMO_MATCH_CORREL_ID;

    4) gmo.matchOptions = MQConstants.MQMO_MATCH_MSG_ID;

    5) gmo.matchOptions =
    MQConstants.MQMO_MATCH_MSG_TOKEN;

    6) gmo.matchOptions = MQConstants.MQMO_MATCH_OFFSET;

    We want to filter data with all the fields. Can you please support the filter for all the fields ?

    we are using the below IBM MQ Jars

    com.ibm.mq
    com.ibm.mq.jmqi
    com.ibm.mq.pcf

    please let us know If any other method available which supports all the fields.



    ------------------------------
    Ranjitha YM
    ------------------------------


  • 2.  RE: Websphere MQ filter Support for more fields
    Best Answer

    IBM Champion
    Posted Mon March 20, 2023 01:35 PM

    Hi Ranjitha,

    The fields you show us that can be matched on are not queue attributes, but message attributes.

    Match Option Message attribute
    MQMO_MATCH_MSG_SEQ_NUMBER MQMD.MsgSeqNumber
    MQMO_MATCH_GROUP_ID MQMD.GroupId
    MQMO_MATCH_CORREL_ID MQMD.CorrelId
    MQMO_MATCH_MSG_ID MQMD.MsgId
    MQMO_MATCH_MSG_TOKEN MQGMO.MsgToken
    MQMO_MATCH_OFFSET MQMD.Offset

    You can use an SQL selector string to match on any field in the MQMD. Some example selector strings are shown in this post. You can use the selector string using the JMS API thus:-

          // Create consumer with selector
          String selector = "Root.MQMD.MsgType = 4";         
          MessageConsumer cons = session.createConsumer(queDest, selector);

    Cheers,
    Morag



    ------------------------------
    Morag Hughson
    MQ Technical Education Specialist
    MQGem Software Limited
    Website: https://www.mqgem.com
    ------------------------------



  • 3.  RE: Websphere MQ filter Support for more fields

    Posted Thu May 04, 2023 07:20 AM

    Can you please let us know how to pass the Message Consumer variable to get function?
    following is our code 

    and which jar do we need to use ? Is it javax.jms.jar?

    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.OutputStream;
    import java.util.Hashtable;
    import com.ibm.mq.MQException;
    import com.ibm.mq.MQGetMessageOptions;
    import com.ibm.mq.MQMessage;
    import com.ibm.mq.MQQueue;
    import com.ibm.mq.MQQueueManager;
    import com.ibm.mq.constants.CMQC;
    import com.ibm.mq.constants.MQConstants;
     
     
     
    public class ReadMQ {
     
    public static void main(String[] args) throws MQException {
     
     
     
    String host = "10.65.139.19";
    String port = "port";
    String username = "UN";
    String password = "Pass";
    String queueManager = "QM";
    String channel = "channel";
     
    MQQueueManager manager;
    MQQueue queue = null;
    boolean getMore = true;
     
    Hashtable<String, Object> mqht = new Hashtable<>();
     
     
    mqht.put(CMQC.CHANNEL_PROPERTY,channel);
    mqht.put(CMQC.HOST_NAME_PROPERTY, host);
    mqht.put(CMQC.PORT_PROPERTY, new Integer(port));
    mqht.put(CMQC.USER_ID_PROPERTY, username);
    mqht.put(CMQC.PASSWORD_PROPERTY, password);
     
     
    manager=new MQQueueManager(queueManager, mqht);
     
    int openOptions = MQConstants.MQOO_BROWSE | MQConstants.MQOO_INPUT_EXCLUSIVE | MQConstants.MQOO_INQUIRE;        
    queue = manager.accessQueue("QA.QUEUE.1",openOptions);
     
    MQGetMessageOptions gmo = new MQGetMessageOptions();
    // MessageSelector Selector =new  MessageSelector(manager);
    // Selector.setFilter("priority", Selector., 0);
     
     
     
    // gmo.options = MQConstants.MQGMO_WAIT + MQConstants.MQGMO_FAIL_IF_QUIESCING
    // + MQConstants.MQGMO_CONVERT
    // + MQConstants.MQGMO_NO_SYNCPOINT;
     
     
    gmo.options = MQConstants.MQGMO_WAIT + MQConstants.MQGMO_FAIL_IF_QUIESCING 
    + MQConstants.MQGMO_CONVERT + MQConstants.MQGMO_BROWSE_NEXT ;
    }
    try {
     
    while(getMore)
    {
    MQMessage message = new MQMessage();
    queue.get(message, gmo);
    byte[] b = new byte[message.getMessageLength()];
    message.readFully(b);
     
    System.out.println(new String(b));
     
    if (IsDestructiveRead) {
     
    //System.out.println(message.expiry);
     
    OutputStream out = new FileOutputStream("C:\\Users\\adminqa\\Documents\\Newfolder\\filename.dat");
    out.write(message.expiry);
    out.close();
     
    manager.commit();
    }
     
    }
     
     
     
    } catch (MQException e) {
     
    if (e.reasonCode == 2033)
    {
    System.out.println("No message available");
    }
     
    if ( (e.completionCode == CMQC.MQCC_FAILED) &&(e.reasonCode == CMQC.MQRC_NO_MSG_AVAILABLE) ) {
     
    }
    else
    {
    System.out.println("MQException: " + e.getLocalizedMessage());
    System.out.println("CC=" + e.completionCode + " : RC=" + e.reasonCode);
    getMore = false;
    }
     
    e.printStackTrace();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
     
    //manager.commit();
    // manager.disconnect();
    // queue.close();
     
    }
     
    }






    ------------------------------
    Ranjitha YM
    ------------------------------



  • 4.  RE: Websphere MQ filter Support for more fields

    Posted Sat May 06, 2023 10:14 PM

    Using com.ibm.mqjms TPL I tried to implement filter, am able to filter messages  based on the below properties 

    But I want to filter messages based on Message Data 

    EX:  we have message data, 1) Manager 2) Employee 3) Lead 4) Manager 

    I want to read messages where message data equal to Manager 

     JMSMessage class
    JMSType
    JMSDeliveryMode
    JMSDeliveryDelay
    JMSDeliveryTime
    JMSExpiration
     JMSPriority
    JMSMessageID
     JMSTimestamp
    JMSCorrelationID
    JMSDestination
    JMSReplyTo
    JMSRedelivered
    JMSXAppID
    JMSXDeliveryCount
    JMSXUserID
    JMS_IBM_Character_Set
    JMS_IBM_Encoding
    JMS_IBM_Format
     JMS_IBM_MsgType
    JMS_IBM_PutApplType
     JMS_IBM_PutDate
    JMS_IBM_PutTime

    import javax.jms.Destination;
    import javax.jms.JMSException;
    import javax.jms.Message;
    import javax.jms.MessageConsumer;
    import javax.jms.Queue;
    import javax.jms.QueueConnection;
    import javax.jms.Session;
    import javax.jms.TextMessage;
     
    import com.ibm.mq.jms.MQQueueConnectionFactory;
    import com.ibm.msg.client.wmq.WMQConstants;
     
    public class IBMMQ_JMSFilter{
     
    public static void main(String[] args) throws NumberFormatException, JMSException {
     
    QueueConnection Queue_Con;
    MessageConsumer consumer;
     
    String host = "host";
    String port = "port";
    String username = "UN";
    String password = "Pass";
    String queueManager = "QM";
    String channel = "QA.APP.SVRCONN";
     
    // Create queue manager connection
    MQQueueConnectionFactory MQ_conFact = new MQQueueConnectionFactory();
    MQ_conFact.setHostName (host);
    MQ_conFact.setPort (Integer.parseInt(port));
    MQ_conFact.setQueueManager (queueManager);
    MQ_conFact.setChannel (channel);
        MQ_conFact.setTransportType (WMQConstants.WMQ_CM_CLIENT);
    //Queue_Con = MQ_conFact.createQueueConnection ();
    Queue_Con = (QueueConnection) MQ_conFact.createConnection(username, password);
     
    //Create session
    Session session = 
    Queue_Con.createSession(false, Session.CLIENT_ACKNOWLEDGE);  // non-transacted session (more)
    // Queue queue = session.createQueue("QA.QUEUE.1"); 
    //Create queue connection
    Destination queDest= session.createQueue("QA.QUEUE.1");
    String selector = "JMS_IBM_MsgType =8";  
      
    consumer = session.createConsumer(queDest, selector);
    //consumer = session.createConsumer(queDest);
    Queue_Con.start();                                             // start the connection (more)
    while (true) {                                           // run forever
    Message msg = consumer.receiveNoWait();                      // blocking! (more)
    // if (! (msg instanceof TextMessage))
    // throw new RuntimeException("Expected a TextMessage");
    TextMessage tm = (TextMessage) msg;
    System.out.println(tm.getText());                      // print message content
    }
    }
     
    }



    ------------------------------
    Ranjitha YM
    ------------------------------



  • 5.  RE: Websphere MQ filter Support for more fields

    0