/* Installs an error handler to deal with a JMS server communication loss. */
DEFINE VARIABLE errorConsumer AS HANDLE NO-UNDO. DEFINE VARIABLE hPubSubSession AS HANDLE NO-UNDO. DEFINE VARIABLE jmsIsOk 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, "errorHandler", OUTPUT errorConsumer). RUN setErrorHandler IN hPubSubSession (errorConsumer). RUN startReceiveMessages IN hPubSubSession. /* Wait forever for messages until the connection with the JMS server is lost with error code "-5" (shutdown the SonicMQ Broker to simulate that). */ RUN waitForMessages IN hPubSubSession ("inWait", THIS-PROCEDURE, ?). IF NOT jmsIsOk THEN DO: MESSAGE "Disocnnectiong from JMS Server... "VIEW-AS ALERT-BOX. RUN deleteSession IN hPubSubSession. END. FUNCTION inWait RETURNS LOGICAL: RETURN jmsIsOk. END. PROCEDURE errorHandler: 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 errorCode AS CHARACTER NO-UNDO. DEFINE VARIABLE errorText AS CHARACTER NO-UNDO. ASSIGN errorCode = DYNAMIC-FUNCTION ('getCharProperty':U IN hMessage, "errorCode") errorText = DYNAMIC-FUNCTION('getText':U IN hMessage). RUN deleteMessage IN hMessage. MESSAGE errorText errorCode VIEW-AS ALERT-BOX. IF errorCode = "-5" THEN jmsIsOk = FALSE. END. |