/* Receives an XML document in a Bytes message. */
DEFINE VARIABLE hPubSubSession AS HANDLE NO-UNDO. DEFINE VARIABLE msgConsumer1 AS HANDLE NO-UNDO. DEFINE VARIABLE stillWaiting AS LOGICAL NO-UNDO INITIAL TRUE. 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, "messageHandler", OUTPUT msgConsumer1). RUN subscribe IN hPubSubSession ("xmlTopic", ?, /* not a durable subscription */ ?, /* no message selector. */ FALSE, /* no local events */ msgConsumer1) NO-ERROR. RUN startReceiveMessages IN hPubSubSession. RUN waitForMessages IN hPubSubSession ("inWait", THIS-PROCEDURE, ?). RUN deleteSession IN hPubSubSession. PROCEDURE messageHandler: DEFINE INPUT PARAMETER hMessage AS HANDLE NO-UNDO. DEFINE INPUT PARAMETER hMessageConsumer AS HANDLE NO-UNDO. DEFINE OUTPUT PARAMETER hReply AS HANDLE NO-UNDO. DEFINE VARIABLE mDoc AS MEMPTR NO-UNDO. DEFINE VARIABLE hDoc AS HANDLE NO-UNDO. DEFINE VARIABLE hRoot AS HANDLE NO-UNDO. mDoc = DYNAMIC-FUNCTION('getMemptr':U IN hMessage). CREATE X-DOCUMENT hDoc. CREATE X-NODEREF hRoot. hDoc:LOAD("memptr", mDoc, FALSE). hDoc:GET-DOCUMENT-ELEMENT(hRoot). RUN GetChildren(hRoot, 1). RUN deleteMessage IN hMessage. stillWaiting = FALSE. END PROCEDURE. PROCEDURE GetChildren: DEFINE INPUT PARAMETER hParent AS HANDLE NO-UNDO. DEFINE INPUT PARAMETER iLevel AS INTEGER NO-UNDO. DEFINE VARIABLE hNodeRef AS HANDLE NO-UNDO. DEFINE VARIABLE ix AS INTEGER NO-UNDO. CREATE X-NODEREF hNodeRef. REPEAT ix = 1 TO hParent:NUM-CHILDREN. hParent:GET-CHILD(hNodeRef, ix). IF hNodeRef:NAME = "#text" THEN MESSAGE "Node text: " hNodeRef:NODE-VALUE. ELSE MESSAGE "Node name: " hNodeRef:NAME. RUN GetChildren(hNodeRef, (iLevel + 1)). END. DELETE OBJECT hNodeRef. END PROCEDURE. FUNCTION inWait RETURNS LOGICAL: RETURN stillWaiting. END. |
/* Publishes an XML document in a Bytes message. */
DEFINE VARIABLE hDoc AS HANDLE NO-UNDO. DEFINE VARIABLE hPubSubSession AS HANDLE NO-UNDO. DEFINE VARIABLE hMesg AS HANDLE NO-UNDO. DEFINE VARIABLE mValue AS MEMPTR NO-UNDO. RUN jms/pubsubsession.p PERSISTENT SET hPubSubSession ("-H localhost -S 5162 "). RUN setBrokerURL IN hPubSubSession ("localhost:2506"). RUN beginSession IN hPubSubSession. RUN createBytesMessage IN hPubSubSession (OUTPUT hMesg). CREATE X-DOCUMENT hDoc. hDoc:LOAD("file", "personal.xml", FALSE). hDoc:SAVE("memptr", mValue). RUN setMemptr IN hMesg(mValue, ?, ?). RUN publish IN hPubSubSession ("xmlTopic", hMesg, ?, ?, ?). SET-SIZE(mValue) = 0. RUN deleteMessage IN hMesg. RUN deleteSession IN hPubSubSession. /* The personal.xml document: <?xml version="1.0" encoding='UTF-8' ?> <personnel> <person id="Irving.Nigrini"> <name><family>Nigrini</family> <given>Irving</given></name> <email>inigrini@subpargolf.com</email> <link manager="Thomas.Roy"/> </person> <person id="Jules.Nigrini"> <name><family>Nigrini</family> <given>Jules</given></name> <email>jnigrini@subpargolf.com</email> <link manager="Thomas.Roy"/> </person> </personnel>*/ |