Try OpenEdge Now
skip to main content
Messaging and ESB
Programming for the OpenEdge Adapter for SonicMQ with the ABL - JMS API : PTP message example : Summary
 

Summary

Complete code for sending a message using a PTP session

The following sample summarizes the steps for sending a message.
/* Sending a message to myqueue */
DEFINE VARIABLE hMessage    AS HANDLE NO-UNDO.
DEFINE VARIABLE hPTPSession AS HANDLE NO-UNDO.
/* Creates PTP session*/
RUN jms/ptpsession.p PERSISTENT SET hPTPSession ("-H localhost -S 5162" ).
/*Connects to the broker */
RUN setBrokerURL IN hPTPSession ("tcp//machinename:2506").
RUN beginSession IN hPTPSession.
/* Create a message */
RUN create...Message IN hPTPSession (OUTPUT hMessage).
RUN set... IN hMessage ("Message").
/*Send the message to "myqueue" */
RUN sendToQueue IN hPTPSession ("myQueue", hMessage, ?, ?, ?)
/* Delete message and session */
RUN deleteMessage IN hMessage.
RUN deleteSession IN hPTPSession.

Complete code for receiving a message using a PTP session

The following sample summarizes the steps for receiving a message.
/* Receives a message from myqueue. */
DEFINE VARIABLE hConsumer   AS HANDLE NO-UNDO.
DEFINE VARIABLE hPTPSession AS HANDLE NO-UNDO.
/* Creates PTP session*/
RUN jms/ptpsession.p PERSISTENT SET hPTPSession ("-H localhost -S 5162" ).
/*Connects to the broker */
RUN setBrokerURL IN hPTPSession ("tcp//machinename:2506").
RUN beginSession IN hPTPSession.
/* Messages received from myqueue are handled by the "myintproc" procedure. */
RUN createMessageConsumer IN hPTPSession
  (THIS-PROCEDURE, "myintproc", OUTPUT hConsumer).
RUN receiveFromQueue IN hPTPSession ("myQueue", ?, hConsumer).
RUN startReceiveMessages IN hPTPSession.
/* Wait to receive the messages. */
WAIT-FOR u1 OF THIS-PROCEDURE.
/* Delete session */
RUN deleteSession IN hPTPSession.
PROCEDURE myintproc:
  DEFINE INPUT  PARAMETER hMessage  AS HANDLE NO-UNDO.
  DEFINE INPUT  PARAMETER hConsumer AS HANDLE NO-UNDO.
  DEFINE OUTPUT PARAMETER hReply    AS HANDLE NO-UNDO.
  /* Business logic here */
  . . .
  /* Delete message */
  RUN deleteMessage IN hMessage.
  APPLY "U1" TO THIS-PROCEDURE.
END.