Progress
External Program
Interfaces


PTP Messaging Examples

The PTP examples consist of a sender and a receiver, and each set should run together. Note that queues cannot be generated on the fly by the clients; queues must be created using the administration tool of the SonicMQ broker.

The path for the PTP messaging examples is:

<Progress_install_dir>\src\samples\sonicmq\adapter\examples\example*.p 

Sending a Message To a Queue and Receiving a Message From a Queue

Examples 18 and 19 send and receive a message from a queue.

Follow these steps to send a message to a queue and receive a message from a queue:

  1. Create the GolfQueue queue using the SonicMQ Explorer. (See the SonicMQ Programming Guide for information about creating queues.)
  2. Run example18.p to send a TextMessage to the GolfQueue.
  3. example18.p 
    /* Sends A Text message to a queue. */ 
    DEFINE VARIABLE ptpsession AS HANDLE. 
    DEFINE VARIABLE messageH AS HANDLE. 
    /* Creates a session object. */ 
    RUN  jms/ptpsession.p PERSISTENT SET ptpsession ("-H localhost -S 5162 "). 
    RUN setBrokerURL IN ptpsession ("localhost:2506"). 
    RUN beginSession IN ptpsession. 
    /* Create a text message */ 
    RUN createTextMessage IN ptpsession (OUTPUT messageH).  
    RUN setText IN messageH ("Golf shoes on sale today."). 
    /* Sends the message to the "GolfQueue" queue */ 
    RUN sendToQueue IN ptpsession ("GolfQueue", messageH, ?, ?, ?). 
    RUN deleteMessage IN messageH. 
    RUN deleteSession IN ptpsession. 
    

  4. Run example19.p to receive a message from the GolfQueue.
  5. example19.p 
    /* Receives a Text message from a queue. */ 
    DEFINE VARIABLE ptpsession AS HANDLE. 
    DEFINE VARIABLE consumerH AS HANDLE. 
    /* Creates a session object. */ 
    RUN  jms/ptpsession.p PERSISTENT SET ptpsession ("-H localhost -S 5162 "). 
    RUN setBrokerURL IN ptpsession ("localhost:2506"). 
    RUN beginSession IN ptpsession. 
    /*  GolfQueue Messages are handled by the "golfHandler" procedure.  */ 
    RUN createMessageConsumer IN ptpsession ( 
                      THIS-PROCEDURE,    /* This proc will handle it */ 
                      "golfHandler",     /* name of internal procedure */ 
                      OUTPUT consumerH). 
    RUN receiveFromQueue IN ptpsession (
                       "GolfQueue",   /* name of queue */ 
                       ?,             /* No message selector */ 
                       consumerH).    /* Handles incoming messages*/ 
    /* Start receiving messages */ 
    RUN startReceiveMessages IN ptpsession. 
    /* Wait to receive the messages. Any other IO-blocked statements can be
       used for receiving messages.  
    */ 
    WAIT-FOR u1 OF THIS-PROCEDURE. 
    
    PROCEDURE golfHandler: 
    DEFINE INPUT PARAMETER messageH AS HANDLE.  
    DEFINE INPUT PARAMETER msgConsumerH AS HANDLE. 
    DEFINE OUTPUT PARAMETER replyH AS HANDLE. 
    /* Display the message - we assume that reply is not required. */ 
    DISPLAY "Message text: " DYNAMIC-FUNCTION('getText':U IN messageH) 
      FORMAT "x(70)". 
    RUN deleteMessage IN messageH. 
    APPLY "U1" TO THIS-PROCEDURE.  
    END. 
    

Achieving Scalable Server Architecture With PTP Queuing

Examples 20 and 21 use PTP queuing to achieve scalable server architecture. Several instances of example20.p (1 of 2) send requests to a single JMS queue and receive replies from servers that run example21.p (1 of 2). You can add more instances to handle an increasing volume of requests.

Follow these steps to run Examples 20 and 21:

  1. Create the requestQueue queue using the SonicMQ Explorer.
  2. Run example20.p (1 of 2) to send requests to the requestQueue queue.
  3. example20.p
    /* Sends a request to a queue and receives a reply from the server. */ 
    DEFINE VARIABLE ptpsession AS HANDLE. 
    DEFINE VARIABLE consumerH AS HANDLE. 
    DEFINE VARIABLE requestH AS HANDLE. 
    DEFINE VARIABLE request AS CHAR. 
    /* Creates a session object. */ 
    RUN  jms/ptpsession.p PERSISTENT SET ptpsession ("-H localhost -S 5162 "). 
    RUN setBrokerURL IN ptpsession ("localhost:2506"). 
    RUN beginSession IN ptpsession. 
    /* Create a text message */ 
    RUN createTextMessage IN ptpsession (OUTPUT requestH). 
    /* Creates a consumer for the reply  */ 
    RUN createMessageConsumer IN ptpsession ( 
                    THIS-PROCEDURE,    /* This proc will handle it */ 
                    "replyHandler",    /* name of internal procedure */ 
                    OUTPUT consumerH). 
    /* Start the reply receiving  */ 
    RUN startReceiveMessages IN ptpsession. 
    /* Loop forever. */ 
    REPEAT: 
      UPDATE request WITH FRAME f1 CENTERED. 
      RUN setText IN requestH (request). 
      /* Sends a request to the requestQueue and handles the reply in the  
         replyHandler internal procedure. */ 
      RUN requestReply IN ptpsession ( "requestQueue", 
                                       requestH, 
                                       ?, /* No reply selector. */ 
                                       consumerH, ?, ?, ?).  
      /* Wait for the reply. */ 
      WAIT-FOR u1 OF THIS-PROCEDURE. 
    END. 
    
    PROCEDURE replyHandler: 
    DEFINE INPUT PARAMETER replyH AS HANDLE. 
    DEFINE INPUT PARAMETER msgConsumerH AS HANDLE. 
    DEFINE OUTPUT PARAMETER responseH AS HANDLE. 
    /* Display the reply from the server. */ 
    DISPLAY "reply text: " DYNAMIC-FUNCTION('getText':U IN replyH) FORMAT 
    "X(30)". 
    RUN deleteMessage IN replyH. 
    APPLY "U1" TO THIS-PROCEDURE. 
    END. 
    

  4. Run example21.p (1 of 2) to receive requests from the requestQueue queue, execute them, and reply to the requester.
  5. example21.p
    /* This example implements a server who gets requests from a JMS queue, 
    executes 
       the request, and replies to the requester. Run several instances of this 
       server and several instances of a client (example20) to observe the  
       scalability of this configuration. */ 
    DEFINE INPUT PARAMETER serverName AS CHAR. 
    DEFINE VARIABLE ptpsession AS HANDLE. 
    DEFINE VARIABLE consumerH AS HANDLE. 
    DEFINE VARIABLE replyMessage AS HANDLE. 
    /* Creates a session object. */ 
    RUN  jms/ptpsession.p PERSISTENT SET ptpsession ("-H localhost -S 5162 "). 
    RUN setBrokerURL IN ptpsession ("localhost:2506"). 
    RUN beginSession IN ptpsession. 
    /* Uses one message for all the replies. */ 
    RUN createTextMessage IN ptpsession (OUTPUT replyMessage). 
    /* receives requests from  the requestQueue */ 
    RUN createMessageConsumer IN ptpsession ( 
                     THIS-PROCEDURE,    /* This proc will handle it */ 
                     "requestHandler",  /* name of internal procedure */ 
                     OUTPUT consumerH). 
    RUN receiveFromQueue IN ptpsession (
                     "requestQueue",   /* request queue */ 
                     ?,                /* No message selector */ 
                     consumerH).       /* Handles the messages */ 
    /* Start receiving requests */ 
    RUN startReceiveMessages IN ptpsession. 
    /* Process requests forever. */ 
    RUN waitForMessages IN ptpsession ("inWait", THIS-PROCEDURE, ?). 
    
    PROCEDURE requestHandler: 
    DEFINE INPUT PARAMETER requestH AS HANDLE. 
    DEFINE INPUT PARAMETER msgConsumerH AS HANDLE. 
    DEFINE OUTPUT PARAMETER replyH AS HANDLE. 
    DEFINE VAR replyText AS CHAR. 
    /* Creates a reply message. The reply is sent automatically when control 
       returns to the 4GL-To-JMS implementation. 
    */ 
    replyText=serverName + " executed " + DYNAMIC-FUNCTION('getText':U IN 
    requestH). 
    RUN deleteMessage IN requestH. 
    replyH = replyMessage. 
    RUN setText IN replyH (replyText). 
    END. 
    
    FUNCTION inWait RETURNS LOGICAL. 
    RETURN true. 
    END. 
    


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