0

I need to retrieve all messages in a pgmq. I tried to use *FIRST as a parameter, but api does not return anything.

     qmhrcvpm(rcvm0200:%size(rcvm0200):'RCVM0200':'*':0:
              '*FIRST':*BLANKS:0:'*SAME':errDS);

Althoug, if i use the key, the api returns the right message :

    qmhrcvpm(rcvm0200:%size(rcvm0200):'RCVM0200':'*':0:
              '*ANY':fldkey:0:'*SAME':errDS);

David : api does not return an error, bytesAvailable of errDs is 0

Mandy : I don't understand your question.

Arsnow
  • 161
  • 1
  • 13
  • When you call with '*FIRST, what is returned in the error data structure? – David G May 03 '19 at 14:23
  • Sounds like this might be a 'new / old' problem, as frequently occurs with RCVMSG and, I would guess, with the API as well. Is there a parameter you need to specify to pick up the whole lot? – MandyShaw May 05 '19 at 12:13

2 Answers2

1

I started writing this as a comment, but as I typed, it is both asking for clarification and providing answers.

What type of message are you retrieving with *ANY and fldkey? If the message is a *REQUEST message, that is your problem. *FIRST, *NEXT, and *PRV all skip request messages.

Or, it is possible that you are retrieving a message somewhere in the job log, but not the active program or procedure when you retrieve by key. *FIRST, *NEXT, and *PRV only retrieve messages for the active program or procedure on the queue. See the documentation for an explanation in the description of *NXTJLMSG or *PRVJLMSG.

I also find in the documentation under the description for Message Key:

If you know the message key of a message you want to receive, you can receive that message without regard to the call message queue containing the message. You can do this by specifying the key in this parameter, the special value '*' for the Call stack entry parameter and the value '0' for the call stack counter parameter. This is useful if the message was sent to a call stack entry that is no longer in the call stack.

Maybe what would work for you, based on the description of *NXTJLMSG would be to use *NXTJLMSG and a key of *TOP or x'00000000'.

jmarkmurphy
  • 11,030
  • 31
  • 59
1

In order to get messages from the job log you will need to use '*PRVJLMSG' or '*NXTJLMSG'.

Pick one based on the order of messages you want to process.

The First call should receive message key x'00000000'.

Then you use the key retrieved to get the next message.

requestKey = x'00000000';
DOU errDS.bytesAvailable > 0 Or rcvm0200.bytesAvailable = 0;
  qmhrcvpm(rcvm0200:%size(rcvm0200):'RCVM0200':'*':0:
          '*NXTJLMSG':requestKey :0:'*SAME':errDS);
  requestKey = rcvm0200.Msgid;

Enddo;
ChrisHiebert
  • 191
  • 2
  • 4