/* Receives a Stream message. */
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 newCustomers topic. The newCustHandler internal procedure handles the list of new customers. */ RUN createMessageConsumer IN hPubSubSession (THIS-PROCEDURE, /* this procedure will handle it */ "newCustHandler", /* name of internal procedure */ OUTPUT hConsumer). RUN subscribe IN hPubSubSession ("NewCustomers", /* 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 to receive the messages. Any other I/O-blocked statements can be used for receiving messages. */ WAIT-FOR u1 OF THIS-PROCEDURE. PROCEDURE newCustHandler: DEFINE INPUT PARAMETER hMessage AS HANDLE NO-UNDO. DEFINE INPUT PARAMETER hMsgConsumer AS HANDLE NO-UNDO. DEFINE OUTPUT PARAMETER hReply AS HANDLE NO-UNDO. /* Display the stream of customer names and customer numbers. The moveToNext function moves the cursor to the next item in the stream and returns the data type of that item. We assume the reply is not required. */ IF NOT DYNAMIC-FUNCTION('getMessageType':U IN hMessage) = "StreamMessage" THEN RETURN. /* Note that the 'moveToNext' functions returns the item's data type. */ DO WHILE NOT DYNAMIC-FUNCTION('endOfStream':U IN hMessage) WITH DOWN: DISPLAY DYNAMIC-FUNCTION('moveToNext':U IN hMessage) DYNAMIC-FUNCTION('readChar':U IN hMessage) DYNAMIC-FUNCTION('moveToNext':U IN hMessage) DYNAMIC-FUNCTION('readInt':U IN hMessage). DOWN. END. RUN deleteMessage IN hMessage. APPLY "U1" TO THIS-PROCEDURE. END PROCEDURE. |
/* Publishing a Stream message. */
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. /* Create a stream message */ RUN createStreamMessage IN hPubSubSession (OUTPUT hMessage). /* Load the message with a list of customer names and custnums. */ FOR EACH customer NO-LOCK: RUN writeString IN hMessage (customer.name). RUN writeInt IN hMessage (customer.custnum). END. /* Publish the message on the NewCustomers topic. */ RUN publish IN hPubSubSession ("NewCustomers", hMessage, ?, ?, ?). |