Try OpenEdge Now
skip to main content
Messaging and ESB
Programming for the OpenEdge Adapter for SonicMQ with the ABL - JMS API : Programming scenarios : Fault tolerance : Example of a "ChangeState" handler (optional)
 
Example of a "ChangeState" handler (optional)
When the connection to the SonicMQ Broker is lost, SonicMQ has the ability to notify the application. A special asynchronous handler, "ChangeState" handler, notifies the client application whenever the state of the SonicMQ Broker changes. The character header property of the message passed to the "ChangeState" handler contains one of the following values: active, reconnecting, failed, or closed. You setup the handler by calling the createChangeStateConsumer procedure after to calling the beginSessionprocedure .

Fault tolerant example

The following code sample shows how to use the createChangeStateConsumer procedure.
RUN createChangeStateConsumer IN hSession
  (THIS-PROCEDURE, "msgHandler", OUTPUT hMessage).
PROCEDURE msgHandler:
  DEFINE INPUT PARAMETER hMessage     AS HANDLE NO-UNDO.
  DEFINE INPUT PARAMETER hMsgConsumer AS HANDLE NO-UNDO.
  DEFINE OUTPUT PARAMETER hReply      AS HANDLE NO-UNDO.
  DEFINE VARIABLE cValue AS CHARACTER NO-UNDO.
  /* cValue will be "active", "reconnecting", "failed", or "closed" */
  cValue = DYNAMIC-FUNCTION("getCharProperty" IN hMessage, "state").
  DISPLAY cValue.
  RUN deleteMessage IN hMessage.
END PROCEDURE.