Release 10.1A: OpenEdge Development:
Messaging and ESB

> ## Summary

> The following code sample summarizes the steps for sending a message:

> Complete code for publish a message using a Pub/Sub session
>     /* Publishes a message to newtopic. */
>     DEFINE VARIABLE pubsubsession AS HANDLE.
>     DEFINE VARIABLE messageH AS HANDLE.
>     /* Creates the Pub/Sub session */
>     RUN  jms/pubsubsession.p PERSISTENT
>         SET pubsubsession ("-H localhost -S 5162 ").
>     /*Connects to the broker */
>     RUN setBrokerURL IN pubsubsession ("tcp://machinename:2506").
>     RUN beginSession IN pubsubsession.
>     /* Create a message */
>     RUN create...Message IN ptpsession (OUTPUT messageH).
>     RUN set... IN messageH ("Message").
>     /* Publish the message on the "newTopic" topic */
>     RUN publish IN pubsubsession ("newTopic", msgH, ?, ?, ?).
>     /* Delete message and session */
>     RUN deleteMessage IN messageH.
>     RUN deleteSession IN pubsubsession.

> The following code sample summarizes the steps for receiving a message:

> Complete code for receiving a message using a Pub/Sub session
>     /* Subscribes and receives a message from myTopic. */
>     DEFINE VARIABLE pubsubsession AS HANDLE.
>     DEFINE VARIABLE consumerH AS HANDLE.
>     /* Creates the Pub/Sub session. */
>     RUN jms/pubsubsession.p PERSISTENT
>         SET pubsubsession ("-H localhost -S 5162 ").
>     /*Connects to the broker */
>     RUN setBrokerURL IN pubsubsession ("ltcp://machinename:2506").
>     RUN beginSession IN pubsubsession.
>     /* Subscriptes to the newTopic topic. Received messages are handled by the
>     myintproc internal procedure.
>     RUN createMessageConsumer
>         IN pubsubsession (THIS-PROCEDURE, "myintproc", OUTPUT consumerH).
>     /* Subscribes to newtopic */
>     RUN SUBSCRIBE IN pubsubsession ("newTopic", ?, ?, NO, consumerH).
>     /* Start receiving requests */
>     RUN startReceiveMessages IN pubsubsession.
>     /* Wait to receive the messages. */
>     WAIT-FOR u1 OF THIS-PROCEDURE.
>     /* Delete session */
>     RUN deleteSession IN ptpsession.
>     PROCEDURE myintproc:
>     DEFINE INPUT PARAMETER messageH AS HANDLE.
>     DEFINE INPUT PARAMETER consumerH AS HANDLE.
>     DEFINE OUTPUT PARAMETER replyH AS HANDLE.
>     /* Business logic here */
>     ...
>         /* Delete message. */
>         RUN deleteMessage IN messageH.
>         APPLY "U1" TO THIS-PROCEDURE.
>     END.

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