PTP message example

A PTP messaging example consists of the basic steps described this topic.

Creating a PTP session

In the following session example, the application creates a session object by calling ptpsession.p persistently.

DEFINE VARIABLE hPTPSession AS HANDLE NO-UNDO.
RUN jms/ptpsession.p PERSISTENT SET hPTPSession ("-H localhost -S 5162" ).

Creating the session object specifies the connection parameters to the JMS-provider Broker. This allows an application to set different session-level attributes before starting the JMS session. The connection to the JMS-provider Broker and the JMS session does not occur until the application calls the beginSession procedure.

Connecting to the broker

In the following connection example, the OpenEdge application connects to the JMS-provider Broker to begin exchanging messages.

RUN setBrokerURL IN hPTPSession ("tcp//machinename:2506").
RUN beginSession IN hPTPSession.

Creating a Message Consumer

The OpenEdge client requires a queue for sending messages. You create a queue using the JMS-provider console (for example, Sonic Management Console). Queues must be defined before starting your session. Then you create a Message Consumer to receive requests from queue, as follows:

RUN createMessageConsumer IN hPTPSession 
  (THIS-PROCEDURE, "myintproc", OUTPUT hConsumer).

Preparing to receive messages

The OpenEdge application begins listening on the queue and prepares to receive messages from the queue, as follows:

RUN receiveFromQueue IN hPTPSession ("myQueue", ?, hConsumer). 
RUN startReceiveMessages IN hPTPSession.
/* Wait to receive the messages. */
WAIT-FOR u1 OF THIS-PROCEDURE.

The Message Consumer (hConsumer handle) listens on myqueue and handles messages using the myintproc internal procedure. The startReceiveMessages procedure starts receipt of incoming messages.

Sending messages to the queue

The application sends a message to the queue using the sendToQueue procedure, as follows:

DEFINE VARIABLE hMessage AS HANDLE NO-UNDO.
/* Code to create message */
RUN sendToQueue IN hPTPSession ("myQueue", hMessage, ?, ?, ?)
Note: The queue must be created on the JMS-provider management console.

Receiving messages from the queue

The Message Consumer receives a message from the queue and executes the business logic.

Deleting a message

The application deletes the messages after it finishes using them, as shown in the following example.

RUN deleteMessage IN hMessage.

PTP Message Summary

To see the full sample code for sending and receiving a message using a PTP session, see PTP message example summary.