/* Using the automatic reply mechanism. Note that the received message
must have a JMSReplyTo header field for this to work. Example7 can be used to receive the reply. */ DEFINE VARIABLE hConsumer AS HANDLE NO-UNDO. DEFINE VARIABLE hPubSubSession AS HANDLE NO-UNDO. /* Creates a session object. */ RUN jms/pubsubsession.p PERSISTENT SET hPubSubSession ("-H localhost -S 5162 "). RUN setBrokerURL IN hPubSubSession ("localhost:2506"). RUN beginSession IN hPubSubSession. /* Subscribe to the GolfTopic topic. Messages are handled by the "golfHandler" internal procedure. */ RUN createMessageConsumer IN hPubSubSession (THIS-PROCEDURE, /* this procedure will handle it */ "golfHandler", /* name of internal procedure */ OUTPUT hConsumer). RUN subscribe IN hPubSubSession ("GolfTopic", /* name of topic */ ?, /* subscription is not durable */ ?, /* no message selector */ FALSE, /* want my own messages too */ hConsumer). /* handles the messages */ /* Start receiving messages */ RUN startReceiveMessages IN hPubSubSession. /* Wait forever to receive messages since "u1" is never applied. */ WAIT-FOR u1 OF THIS-PROCEDURE. PROCEDURE golfHandler: DEFINE INPUT PARAMETER hMessage AS HANDLE NO-UNDO. DEFINE INPUT PARAMETER hMsgConsumer AS HANDLE NO-UNDO. DEFINE OUTPUT PARAMETER hReply AS HANDLE NO-UNDO. /* Creates a reply message. The reply is published automatically when control returns to the ABL–JMS implementation.*/ DISPLAY DYNAMIC-FUNCTION('getText':U IN hMessage) FORMAT "x(60)". IF DYNAMIC-FUNCTION('hasReplyTo':U IN hMessage) THEN DO: RUN createTextMessage IN hPubSubSession (OUTPUT hReply). RUN setText IN hReply ("Will bid. Send data in sportsXML format."). END. RUN deleteMessage IN hMessage. END PROCEDURE. |
/* Replying explicitly. Note that the received message must have a
JMSReplyTo header field for this to work. Example7 can be used to receive the reply. */ DEFINE VARIABLE msgConsumer AS HANDLE NO-UNDO. DEFINE VARIABLE hPubSubSession AS HANDLE NO-UNDO. /* Creates a session object. */ RUN jms/pubsubsession.p PERSISTENT SET hPubSubSession ("-H localhost -S 5162 "). RUN setBrokerURL IN hPubSubSession ("localhost:2506"). RUN beginSession IN hPubSubSession. RUN createMessageConsumer IN hPubSubSession (THIS-PROCEDURE, /* this procedure will handle it */ "messageHandler", /* name of internal procedure */ OUTPUT msgConsumer). RUN subscribe IN hPubSubSession ("GolfTopic", ?, /* no durable subscription */ ?, /* no message selector */ FALSE, /* want to get my own publications */ msgConsumer). RUN startReceiveMessages IN hPubSubSession. /* Wait forever to receive messages since "u1" is never applied. */ WAIT-FOR u1 OF THIS-PROCEDURE. RUN deleteSession IN hPubSubSession. PROCEDURE messageHandler: DEFINE INPUT PARAMETER hMessage AS HANDLE NO-UNDO. DEFINE INPUT PARAMETER hMessageConsumer AS HANDLE NO-UNDO. /* hAutoReply is not used in this example */ DEFINE OUTPUT PARAMETER hAutoReply AS HANDLE NO-UNDO. DEFINE VARIABLE hReply AS HANDLE NO-UNDO. DISPLAY DYNAMIC-FUNCTION('getText':U IN hMessage) FORMAT "x(60)". IF NOT DYNAMIC-FUNCTION('hasReplyTo':U IN hMessage) THEN RETURN. /* Publishes a reply explicitly - using the publish call. */ RUN createTextMessage IN hPubSubSession (OUTPUT hReply). RUN setText IN hReply("Will bid. Send data in sportsXML format."). RUN publish IN hPubSubSession (DYNAMIC-FUNCTION ('getJMSReplyTo':U IN hMessage), hReply, ?, ?, ?). RUN deleteMessage IN hMessage. /* After we have sent the message, delete it. */ RUN deleteMessage IN hReply. END PROCEDURE. |
/* Publishes a message and receives a reply. */
DEFINE VARIABLE hConsumer AS HANDLE NO-UNDO. DEFINE VARIABLE hMessage AS HANDLE NO-UNDO. DEFINE VARIABLE hPubSubSession AS HANDLE NO-UNDO. /* Creates a session object. */ RUN jms/pubsubsession.p PERSISTENT SET hPubSubSession ("-H localhost -S 5162 "). RUN setBrokerURL IN hPubSubSession ("localhost:2506"). RUN beginSession IN hPubSubSession. /* Start receiving messages */ RUN startReceiveMessages IN hPubSubSession. /* Create a text message */ RUN createTextMessage IN hPubSubSession (OUTPUT hMessage). RUN setText IN hMessage ("Golf shoes on sale today."). /* Creates a consumer for the reply */ RUN createMessageConsumer IN hPubSubSession (THIS-PROCEDURE, /* this procedure will handle it */ "golfHandler", /* name of internal procedure */ OUTPUT hConsumer). /* Publish the message onto the Golf topic. Handle the reply in the golfHandler internal procedure. */ RUN requestReply IN hPubSubSession ("GolfTopic", hMessage, ?, /* No reply selector. */ hConsumer, ?, ?, ?). RUN deleteMessage IN hMessage. /* Wait forever to receive messages since "u1" is never applied. */ WAIT-FOR u1 OF THIS-PROCEDURE. PROCEDURE golfHandler: DEFINE INPUT PARAMETER hReply AS HANDLE NO-UNDO. DEFINE INPUT PARAMETER hMsgConsumer AS HANDLE NO-UNDO. DEFINE OUTPUT PARAMETER responseH AS HANDLE NO-UNDO. /* Display the reply - we are not sending a response. */ DISPLAY "reply text: " DYNAMIC-FUNCTION('getText':U IN hReply) FORMAT "X(30)". RUN deleteMessage IN hReply. END PROCEDURE. |