ibm-midrangejt400

ibm jt400 get data queue number of entries


I'm using Data Queues in AS400/iSeries and read from one using jdbc jt400 library.

As it's a producer(AS400)/consumer(myapp) pattern, I want to check how many entries in the data queue are now, and measure if my app is working fast enough or I need to change something.

I can get the max length/size of the data queue, but not the current length/size.

How can I get or calculate that value?

I can use a rpg program and call it, but prefer a jt400/jdbc solution.

Thanks

I edit this question to add code that should do this task but I get an Exception:

    String pname = "/QSYS.LIB/QMHQRDQD.PGM";
    int param0_size = 120; // RDQD0100 size
    int size = -1;
    ProgramCall spgm = new ProgramCall(as400);
    ProgramParameter[] params = new ProgramParameter[4];
    params[0] = new ProgramParameter(param0_size);
    AS400Bin4 length = new AS400Bin4();
    params[1]  = new ProgramParameter(length.toBytes(param0_size));
    AS400Text formatname = new AS400Text(8);
    params[2] = new ProgramParameter(formatname.toBytes("RDQD0100"));
    AS400Text dataqueuename = new AS400Text(20);
    params[3] = new ProgramParameter(dataqueuename.toBytes("DTQDTQ    LIBFIC    "));
    byte[] RDQD0100 = new byte[120];

    try {
        spgm.setProgram(pname, params);
        if (spgm.run() == true) {
            AS400Text out = new AS400Text(param0_size);
            RDQD0100 = out.toBytes(params[0].getOutputData());
            ByteBuffer bb = ByteBuffer.wrap(RDQD0100);
            bb.position(76);  // Number of entries currently allocated
            size = bb.getInt();
        }
    }
    catch (Exception e){
        Logger.error(" ERROR {} ", e);
    }

    return size;

I get always -1 as answer and an Exception in line RDQD0100 = out.toB..

The exception is

java.lang.ClassCastException: [B cannot be cast to java.base/java.lang.String

Any clues? Thanks again


Solution

  • Using base JT400, there doesn't appear to be a way to get the number of entries in a data queue.

    You could use the QMHQRDQD api to get the number of messages in the queue.