Try OpenEdge Now
skip to main content
Messaging and ESB
Messaging Examples : Pub/Sub messaging examples : Installing an error handler for synchronous errors
 

Installing an error handler for synchronous errors

The procedure example17.p publishes a TextMessage to a nonexistent topic and handles the error conditions, as shown:

example17.p

/* Publishes A Text message to an illegal topic name and handles the
   error conditions. */
DEFINE VARIABLE hPubSubSession AS HANDLE  NO-UNDO.
DEFINE VARIABLE hMessage       AS HANDLE  NO-UNDO.
DEFINE VARIABLE lSuccess       AS LOGICAL NO-UNDO.
/* Creates a session object. */
RUN jms/pubsubsession.p PERSISTENT SET hPubSubSession
  ("-H localhost -S 5162 ").
RUN setNoErrorDisplay IN hPubSubSession (true).
RUN setBrokerURL IN hPubSubSession ("localhost:2506").
RUN beginSession IN hPubSubSession.
/* Create a text message */
RUN createTextMessage IN hPubSubSession (OUTPUT hMessage).
RUN setText IN hMessage ("Golf shoes on sale today.").
/* Publish the message on the illegal '*' topic */
DO ON ERROR UNDO, LEAVE:
  RUN publish IN hPubSubSession ("*", hMessage, ?, ?, ?).
  lSuccess = TRUE.
END.
If NOT lSuccess THEN
  MESSAGE "Failed to publish to topic '*': " RETURN-VALUE VIEW-AS ALERT-BOX.
RUN deleteMessage IN hMessage.
RUN deleteSession IN hPubSubSession.