Read a message Queue without loosing messages

1160 pts.
Tags:
CL
CL/400
I have developed a CL pgm, which monitors a message queue and in case a job ended abnormally message appears on that message queue, the system sends a email message to certain users. This is working fine, however the user whose message queue i monitor does not receive any message as my program removes the message after reading the message queue as it has to continue reading subsequent message that keep coming into the queue even after the job ended abnormally message is received. How can i ensure that the message is not removed even after it is read by the program at the same time the program keeps waiting and reading the latest message that has entered the message queue.

Answer Wiki

Thanks. We'll let you know when a new response is added.

<b>Hi Johnson, I have 2 CL’s to monitore this situation:</b>


PGM PARM(&MSGQ &MSGLIB &MRK)
DCL VAR(&PRINT) TYPE(*CHAR) LEN(08)
DCL VAR(&MSGQ) TYPE(*CHAR) LEN(10)
DCL VAR(&MSGLIB) TYPE(*CHAR) LEN(10)
DCL VAR(&MSGID) TYPE(*CHAR) LEN(7)
DCL VAR(&MRK) TYPE(*CHAR) LEN(4)
DCL VAR(&MSG) TYPE(*CHAR) LEN(75)
DCL VAR(&MSG2) TYPE(*CHAR) LEN(3000)
DCL VAR(&MSGX) TYPE(*CHAR) LEN(5000)
DCL VAR(&SEV) TYPE(*DEC) LEN(2)
DCL VAR(&SENDER) TYPE(*CHAR) LEN(80)
DCL VAR(&SEVA) TYPE(*CHAR) LEN(2)

RCVMSG MSGQ(&MSGLIB/&MSGQ) MSGKEY(&MRK) RMV(*NO) +
MSG(&MSG) SECLVL(&MSG2) MSGID(&MSGID) +
SEV(&SEV) SENDER(&SENDER)

CHGVAR VAR(&SEVA) VALUE(&SEV)
CHGVAR VAR(&MSGX) VALUE(‘MESSAGE:’ *BCAT &MSG *BCAT +
‘:/N’ *BCAT &MSG2 *TCAT ‘:/N ID:’ *BCAT +
&MSGID *TCAT ‘:/N SEVERITY:’ *BCAT &SEVA +
*TCAT ‘:/N SENDER:’ *BCAT &SENDER)

IF COND(&SEV > 40) THEN(DO)
IF COND((&MSGID = ‘CPF1393′) *OR (&MSGID = +
‘CPA5201′) *OR (&MSGID = ‘CPA5305′) *OR +
(&MSGID = ‘CPI7B43′) *OR (&MSGID = +
‘CPF3395′) *OR (&MSGID = ‘CPF3397′) *OR +
(&MSGID = ‘CPI9380′) *OR (&MSGID = +
‘CPA57EF’) *OR (&MSGID = ‘CPF1189′) *OR +
(&MSGID = ‘CPA5243′) *OR (&MSGID = +
‘CPI404F’)) THEN(GOTO CMDLBL(END))

IF COND(&MSGID = ‘CPF6792′) THEN(DO)
ENDDO

SNDDST TYPE(*LMSG) TOINTNET((example1@gmail.com) +
(example2@gmail.com *CC) +
(example3@gmail.com)) DSTD(‘Error on +
QSYSOPR MESSAGE’) MSG(‘**** This is a Automatic +
Message ****’) +
LONGMSG(&MSGX) SUBJECT(‘Error – iSeries +
QSYSOPR MESSAGE ‘)
ENDDO
end:
ENDPGM


PGM
CHGMSGQ MSGQ(QSYSOPR) DLVRY(*BREAK) PGM(TOPAS/MSG_GET *ALWRPY)
LOOP: +
DLYJOB DLY(600)
GOTO CMDLBL(LOOP)
ENDPGM

***** On my Subsystem QPGMR ****

Work with Active Jobs
05/08/08 16:29:23
CPU %: .0 Elapsed time: 00:00:00 Active jobs: 259
Opt Subsystem/Job User Type CPU % Function Status
QPGMR QSYS SBS .0 DEQW
INACTMSGQ OPERATOR PJ .0 DLY-300 DLYW
MSG_MAIL OPERATOR S PJ .0 DLY-600 DLYW

Regards,
Roberto

Hi,

You need to specify RMVMSG(*NO) and use a combination of MSGTYPE(*NEXT) and MSGKEY. Once you’ve retrieved your first message, you should have a key value.

I probably have an example somewhere if you need it.

Regards,

Martin Gilbert.

Hi Martin,

Can u pass on the example.? Thanks for the reply.

Regards.

Johnson

Discuss This Question: 3  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Gilly400
    Hi, Here's a basic example (this is looking at messages in QSYSOPR) :- PGM DCL VAR(&KEYVAR) TYPE(*CHAR) LEN(4) DCL VAR(&LEVEL1) TYPE(*CHAR) LEN(132) DCL VAR(&LEVEL2) TYPE(*CHAR) LEN(3000) DCL VAR(&MSGID) TYPE(*CHAR) LEN(7) DCL VAR(&SENDER) TYPE(*CHAR) LEN(80) /* get the first message available */ RCVMSG MSGQ(QSYSOPR) MSGTYPE(*FIRST) WAIT(*MAX) + RMV(*NO) KEYVAR(&KEYVAR) MSG(&LEVEL1) + SECLVL(&LEVEL2) MSGID(&MSGID) SENDER(&SENDER) NEXT: /* Process your message data here */ /* get the next message */ RCVMSG MSGQ(QSYSOPR) MSGTYPE(*NEXT) MSGKEY(&KEYVAR) + WAIT(*MAX) RMV(*NO) KEYVAR(&KEYVAR) + MSG(&LEVEL1) SECLVL(&LEVEL2) + MSGID(&MSGID) SENDER(&SENDER) GOTO NEXT ENDPGM
    23,730 pointsBadges:
    report
  • Fahim
    Hi Gilly,

     What does &KeyVar, &Level1, &level2 mean? And also while reading the second messgae do we need to increment anything?
    10 pointsBadges:
    report
  • TomLiotta
    Prompt the RCVMSG command with <F4> to read the help text for the parameters or read the Information Center topic on RCVMSG to see what each parameter means. If some aspect doesn't make sense, ask about it with a clear question. And it's not necessary to increment anything to receive the next message. The MSGTYPE(*NEXT) and MSGKEY(&KEYVAR) parameters tell the command how to behave. -- Tom
    125,585 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following