Kbase P89005: How to send messages using Microsoft Queuing ?
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  11/25/2008 |
|
Status: Verified
GOAL:
How to send messages using Microsoft Queuing ?
GOAL:
How to use MSMQ in 4GL?
FACT(s) (Environment):
Progress 9.x
OpenEdge 10.x
Windows
FIX:
Send.p shows how to create a MSMQ queue and send a message.
Use a private queue pathname when your machine is not part of a Windows domain.
/* send.p -- begin */
DEF VAR hQueueInfo AS COM-HANDLE.
DEF VAR hQueueDest AS COM-HANDLE.
DEF VAR hMsg AS COM-HANDLE.
CREATE "MSMQ.MSMQQueueInfo" hQueueInfo.
CREATE "MSMQ.MSMQMessage" hMsg.
hQueueInfo:PATHNAME = ".\PRIVATE$\testqueue".
hQueueInfo:LABEL = "TestLabel".
hQueueInfo:CREATE( , ) NO-ERROR.
IF ERROR-STATUS:GET-MESSAGE(1) <> '' THEN DO:
MESSAGE "The queue already exists. Program will continue to send messages"
VIEW-AS ALERT-BOX.
END.
hQueueDest = hQueueInfo:OPEN( 2, 0 ).
hMsg:LABEL = "Message Label".
hMsg:Body = "Message Body " + STRING( TODAY ) + " " + STRING( TIME, "HH:MM:SS" ).
hMsg:Send( hQueueDest, ).
hQueueDest:CLOSE().
/* send.p -- end */
Receive.p shows how to retrieve a message synchronously.
/* receive.p -- begin */
/* this sample will retrieve message synchronously */
/* see MSDN documentation for retrieving messages asynchronously */
DEF VAR hQueueInfo AS COM-HANDLE.
DEF VAR hQueueDest AS COM-HANDLE.
DEF VAR hQueue AS COM-HANDLE.
DEF VAR hMsg AS COM-HANDLE.
CREATE "MSMQ.MSMQQueueInfo" hQueueInfo.
CREATE "MSMQ.MSMQMessage" hMsg.
hQueueInfo:PATHNAME = ".\PRIVATE$\testqueue" NO-ERROR.
hQueueInfo:LABEL = "TestLabel".
hQueue = hQueueInfo:OPEN( 1 , 0 ).
hMsg = hQueue:Receive( ,, TRUE, 1000 ) .
IF NOT VALID-HANDLE( hMsg ) THEN DO:
MESSAGE "No Message available" VIEW-AS ALERT-BOX.
RETURN.
END.
MESSAGE hMsg:LABEL SKIP
hMsg:Body
VIEW-AS ALERT-BOX.
hQueue:CLOSE().
/* receive.p -- end */