Release 10.1A: OpenEdge Development:
Messaging and ESB

> ## Installing an error handler to handle an asynchronous error

> The procedure example16.p (1 of 2) installs an error handler to detect a JMS server communication loss.

> | To install an error handler to handle an asynchronous error:

> 1. Run example16.p (1 of 2), as shown:

> example16.p
>     /* Installs an error handler to deal with a JMS server communication loss.
>     */
>     DEFINE VARIABLE pubsubsession AS HANDLE.
>     DEFINE VARIABLE errorConsumer AS HANDLE.
>     DEFINE VARIABLE jmsIsOk AS LOGICAL INIT yes.
>     RUN jms/pubsubsession.p PERSISTENT SET pubsubsession
>                                       ("-H localhost -S 5162 ").
>     RUN setBrokerURL IN pubsubsession ("localhost:2506").
>     RUN beginSession IN pubsubsession.
>     RUN createMessageConsumer IN pubsubsession(THIS-PROCEDURE,
>                                                "errorHandler",
>                                                OUTPUT errorConsumer).
>     RUN setErrorHandler IN pubsubsession (errorConsumer).
>     RUN startReceiveMessages IN pubsubsession.
>     /* 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 pubsubsession ("inWait", THIS-PROCEDURE, ?).
>     IF NOT jmsIsOk THEN
>     DO:
>         MESSAGE "Disocnnectiong from JMS Server... "VIEW-AS ALERT-BOX.
>         RUN deleteSession IN pubsubsession.
>     END.
>     FUNCTION inWait RETURNS LOGICAL.
>         RETURN jmsIsOk.
>     END.
>     PROCEDURE errorHandler:
>     DEFINE INPUT PARAMETER messageH AS HANDLE NO-UNDO.
>     DEFINE INPUT PARAMETER messageConsumerH AS HANDLE NO-UNDO.
>     DEFINE OUTPUT PARAMETER replyH AS HANDLE NO-UNDO.
>     DEFINE VAR errorCode AS CHAR NO-UNDO.
>     DEFINE VAR errorText AS CHAR NO-UNDO.
>         ASSIGN
>           errorCode = DYNAMIC-FUNCTION
>             ('getCharProperty':U IN messageH, "errorCode")
>         errorText = DYNAMIC-FUNCTION('getText':U IN messageH).
>         RUN deleteMessage IN messageH.
>         MESSAGE errorText errorCode VIEW-AS ALERT-BOX.
>         IF errorCode = "-5" THEN
>             jmsIsOk = no.
>     END.

> 2. Shut down the SonicMQ Broker to simulate the communication loss.

Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095