Search code examples
javaibm-midrangejt400

JT400 - get messages from Queue


I would like to get messages in AS400 from a queue other than a queue from QSYS.LIB. I am using the following code that runs well, only if I use a queue from within QSYS.LIB:

public String getMessagesFromQsysopr(boolean needReply) {


    String messageStr = "";
    try {

    MessageQueue queue = new MessageQueue(this.as400, "/qsys.lib/qsysopr.msgq");
 // want only inquiry messages
    queue.setSelectMessagesNeedReply(needReply);
    queue.setSelectMessagesNoNeedReply(!needReply);
    queue.setSelectSendersCopyMessagesNeedReply(needReply);
    queue.setListDirection(false);

    Enumeration e = queue.getMessages();
    while (e.hasMoreElements()) {
        QueuedMessage message = (QueuedMessage) e.nextElement();
        messageStr += message.getText()+"\n";
    }


} catch (Exception e) {
    e.printStackTrace();
}

If I replace the /qsys.lib/qsysopr.msgq for any other queue from other lib, like for example "/yaclib.lib/queueName.msgq" I get the following error:

com.ibm.as400.access.IllegalPathNameException: /yaclib.lib/queueName.msgq: Object not in QSYS file system. at com.ibm.as400.access.QSYSObjectPathName.parse(QSYSObjectPathName.java:599) at com.ibm.as400.access.QSYSObjectPathName.(QSYSObjectPathName.java:169) at com.ibm.as400.access.QSYSObjectPathName.(QSYSObjectPathName.java:177) at com.ibm.as400.access.MessageQueue.(MessageQueue.java:299) at br.com.operation.AS400Inspector.getMessagesFromYaclib(AS400Inspector.java:225) at br.com.operation.Main.main(Main.java:43)

Question 1: What am I doing wrong?

Question 2: Is there any way to limit the messages that don't need reply? Like get messages after a specific date or just the last 2 day messages?

Thanks.


Solution

  • @user2338816 is correct.

    QSYS is a special library; it actually contains every other library in the system. From a 5250 session, WRKOBJ *ALL *LIB will confirm that every library is the system is in the QSYS library. Interestingly, QSYS itself is contained in QSYS.

    When using IFS naming, to refer to a library of YACLIB.LIB, you need to use /QSYS.LIB/YACLIB.LIB

    As far as selecting by date, no there's no way to do that. If you look at the java docs the closest you'll find is NEW, NEWEST, OLD, OLDEST