Try OpenEdge Now
skip to main content
Messaging and ESB
Programming for the OpenEdge Adapter for SonicMQ with the ABL - JMS API : Programming scenarios : TempTableMessage
 

TempTableMessage

OpenEdge applications use temp-tables for data. The new TempTableMessage supports using temp-tables for JMS messaging. The XMLMessage is the basis for the TempTableMessage. A non-OpenEdge application receives a TempTableMessage as an XMLMessage. The JMS header property signals an OpenEdge application that the incoming message is a TempTableMessage.
For more information on accessing the examples files, see OpenEdge messages.
For an alphabetical API reference, see ABL - JMS API Reference.
The following example shows sending a TempTableMessage.

ttmgs_send.p

DEFINE VARIABLE hMessage AS HANDLE  NO-UNDO.
DEFINE VARIABLE hSession AS HANDLE  NO-UNDO.
DEFINE VARIABLE numRecs  AS INTEGER NO-UNDO.
DEFINE VARIABLE ptp      AS LOGICAL NO-UNDO.
DEFINE VARIABLE ttH      AS HANDLE  NO-UNDO.
DEFINE TEMP-TABLE ttCustomer NO-UNDO LIKE customer.
/* Creates a session object. */
RUN jms/jmssession.p PERSISTENT SET hSession ("-SMQConnect").
RUN setBrokerURL IN hSession ("localhost:2506").
RUN beginSession IN hSession.
FOR EACH customer NO-LOCK:
  CREATE ttCustomer.
  ASSIGN
    ttCustomer.CustNum    = customer.CustNum
    ttCustomer.Name       = customer.Name
    ttCustomer.Address    = customer.Address
    ttCustomer.Address2   = customer.Address2
    ttCustomer.City       = customer.City
    ttCustomer.State      = customer.State
    ttCustomer.PostalCode = customer.PostalCode
    ttCustomer.Country    = customer.Country
    numRecs               = numRecs + 1.
END.
ttH = TEMP-TABLE ttCustomer:HANDLE.
RUN createTemptableMessage IN hSession (OUTPUT hMessage).
RUN setTempTable IN hMessage (ttH, ?, TRUE).
IF ptp THEN
  RUN sendToQueue IN hSession ("SampleQ1", hMessage, ?, ?, ?).
ELSE
  RUN PUBLISH IN hSession ("TestTopic", hMessage, ?, ?, ?).
RUN deleteMessage IN hMessage.
DELETE ttCustomer.
MESSAGE "Number of records processed: " + STRING(numRecs).
RUN createTextMessage in hSession (OUTPUT hMessage).
RUN setText IN hMessage (STRING(numRecs)).
IF ptp THEN
  RUN sendToQueue IN hSession ("SampleQ1", hMessage, ?, ?, ?).
ELSE
  RUN PUBLISH IN hSession ("TestTopic", hMessage, ?, ?, ?).
RUN deleteMessage IN hMessage.
RUN deleteSession IN hSession.

ttmsg_recv.p

The following example shows receiving a TempTableMessage.
DEFINE VARIABLE hMsgConsumer AS HANDLE  NO-UNDO.
DEFINE VARIABLE hMesg        AS HANDLE  NO-UNDO.
DEFINE VARIABLE hSession     AS HANDLE  NO-UNDO.
DEFINE VARIABLE numRecsRead  AS INTEGER NO-UNDO.
DEFINE VARIABLE ptp          AS LOGICAL NO-UNDO.
DEFINE VARIABLE stillWaiting AS LOGICAL NO-UNDO INITIAL TRUE.
RUN jms/jmssession.p PERSISTENT SET hSession ("-SMQConnect").
RUN setBrokerURL IN hSession ("localhost:2506").
RUN beginSession IN hSession.
RUN createMessageConsumer IN hSession
  (THIS-PROCEDURE,   /* this procedure will handle it */
   "messageHandler", /* name of internal procedure */
   OUTPUT hMsgConsumer).
IF ptp THEN
  RUN receiveFromQueue IN hSession ("SampleQ1", ?, hMsgConsumer).
ELSE
  RUN subscribe IN hSession
    ("TestTopic",
     ?,    /* durable subscription */
     ?,    /* no message selector */
     TRUE, /* want to get my own publications */
     hMsgConsumer).
RUN startReceiveMessages IN hSession.
RUN waitForMessages IN hSession ("inWait", THIS-PROCEDURE, ?).
RUN deleteSession IN hSession.
MESSAGE "Number of records processed: " + STRING(numRecsRead).
PROCEDURE messageHandler:
  DEFINE INPUT PARAMETER hMessage         AS HANDLE NO-UNDO.
  DEFINE INPUT PARAMETER hMessageConsumer AS HANDLE NO-UNDO.
  /* hAutoReply is not used in this example */
  DEFINE OUTPUT PARAMETER hAutoReply      AS HANDLE NO-UNDO.
  DEFINE VARIABLE bh1  AS HANDLE NO-UNDO.
  DEFINE VARIABLE bh2  AS HANDLE NO-UNDO.
  DEFINE VARIABLE qh1  AS HANDLE NO-UNDO.
  DEFINE VARIABLE ttH1 AS HANDLE NO-UNDO.
  IF DYNAMIC-FUNCTION("getMessageType" in hMessage) =
    "TemptableMessage" THEN DO:
    ttH1 = DYNAMIC-FUNCTION("getTempTable" IN hMessage, ?, ?, ?).
    numRecsRead = numRecsRead + 1.
    bh1 = tth1:DEFAULT-BUFFER-HANDLE.
    CREATE QUERY qh1.
    qh1:SET-BUFFERS(bh1).
    qh1:QUERY-PREPARE("for each tcust").
    qh1:QUERY-OPEN().
    qh1:GET-FIRST.
    REPEAT WHILE NOT qh1:QUERY-OFF-END:
      bh2 = bh1:BUFFER-FIELD("name").
      MESSAGE bh2:STRING-VALUE().
      qh1:GET-NEXT.
      DELETE OBJECT bh2.
    END.
    qh1:QUERY-CLOSE.
DELETE OBJECT ttH1.
DELETE OBJECT qh1.
  END. /* getMessageType */
  ELSE
    stillWaiting = FALSE.
  RUN deleteMessage IN hMessage.
END PROCEDURE.
FUNCTION inWait RETURNS LOGICAL:
  RETURN stillWaiting.
END.