/* Publishes a message to newtopic. */
DEFINE VARIABLE hMessage AS HANDLE NO-UNDO. DEFINE VARIABLE hPubSubSession AS HANDLE NO-UNDO. /* Creates the Pub/Sub session */ RUN jms/pubsubsession.p PERSISTENT SET hPubSubSession ("-H localhost -S 5162 "). /*Connects to the broker */ RUN setBrokerURL IN hPubSubSession ("tcp://machinename:2506"). RUN beginSession IN hPubSubSession. /* Create a message */ RUN create...Message IN hPTPSession (OUTPUT hMessage). RUN set... IN hMessage ("Message"). /* Publish the message on the "newTopic" topic */ RUN publish IN hPubSubSession ("newTopic", hMessage, ?, ?, ?). /* Delete message and session */ RUN deleteMessage IN hMessage. RUN deleteSession IN hPubSubSession. |
/* Subscribes and receives a message from myTopic. */
DEFINE VARIABLE hConsumer AS HANDLE NO-UNDO. DEFINE VARIABLE hPubSubSession AS HANDLE NO-UNDO. /* Creates the Pub/Sub session. */ RUN jms/pubsubsession.p PERSISTENT SET hPubSubSession ("-H localhost -S 5162 "). /*Connects to the broker */ RUN setBrokerURL IN hPubSubSession ("ltcp://machinename:2506"). RUN beginSession IN hPubSubSession. /* Subscriptes to the newTopic topic. Received messages are handled by the myintproc internal procedure. */ RUN createMessageConsumer IN hPubSubSession (THIS-PROCEDURE, "myintproc", OUTPUT hConsumer). /* Subscribes to newtopic */ RUN SUBSCRIBE IN hPubSubSession ("newTopic", ?, ?, NO, hConsumer). /* Start receiving requests */ RUN startReceiveMessages IN hPubSubSession. /* Wait to receive the messages. */ WAIT-FOR u1 OF THIS-PROCEDURE. /* Delete session */ RUN deleteSession IN hPTPSession. PROCEDURE myintproc: DEFINE INPUT PARAMETER hMessage AS HANDLE NO-UNDO. DEFINE INPUT PARAMETER hConsumer AS HANDLE NO-UNDO. DEFINE OUTPUT PARAMETER hReply AS HANDLE NO-UNDO. /* Business logic here */ . . . /* Delete message. */ RUN deleteMessage IN hMessage. APPLY "U1" TO THIS-PROCEDURE. END. |