SAS 9.1.3 Integration Technologies » Developer's Guide


Application Messaging Overview
Supported Messaging Interface Versions
WebSphere MQ Configuration and Usage
Configuring WebSphere MQ with the WebSphere MQ Explorer
Polling Message Queues from the Object Spawner
Configuring Multiple Clients To Read From a Single Queue
Configuring WebSphere MQ to Trigger SAS
WebSphere MQ Interface
Writing WebSphere MQ Applications
WebSphere MQ Code Samples
WebSphere MQ CALL Routines
MSMQ Interface
Writing MSMQ Applications
MSMQ Code Samples
MSMQ Call Routines
Common Messaging Interface
Writing Applications
Using TIB/Rendezvous with the Common Interface
TIB/Rendezvous Coding Example
TIB/Rendezvous Certified Messaging Coding Example
Using a Repository with Application Messaging
SAS CALL Routines for the Common Interface
Attachment Layout for Websphere MQ and MSMQ Through Common Messaging Interface
Attachment Layout for TIB/Rendezvous
Attachment Error Handling for Common Messaging Interface
Application Messaging

Sample Trigger Programs

mqclient.sas

   data _null_;

      length msg $ 200;
      length qid2 tid rc 8;
      length map $80;
      length recv1 $50;
      length event  $10;
      length rpname $256;
      length type $8;
      length qual1 qual2 $40;

      libname out '.';

      tid=0;
      rc=0;
      put '----';
      put 'Call INIT';
      CALL INIT(tid, 'MQSERIES', rc);
      if rc ^= 0 then do;
         put 'INIT: failed';
         msg = sysmsg();
         put msg;
      end;
      else put 'INIT: succeeded';

      rc=0;
      qid=0;
      put '----';
      put 'Call OPENQUEUE to open the response queue';
      CALL OPENQUEUE(qid, tid, 'XPQMGR:REPLY', 'fetch', 
         rc, "POLL(TIMEOUT=20)");
      if rc ^= 0 then do;
         put 'OPENQUEUE: failed';
         msg = sysmsg();
         put msg;
      end;
      else put 'OPENQUEUE: succeeded';

      rc=0;
      qid2=0;
      put 'Call OPENQUEUE to open the request queue on qid2';
      CALL OPENQUEUE(qid2, tid, 'XPQMGR:AIX.TRIGQUEUE', 
         'DELIVERY', rc, "POLL(Timeout=15)");
      if rc ^= 0 then do;
         put 'OPENQUEUE: failed';
         msg = sysmsg();
         put msg;
      end;
      else put 'OPENQUEUE: succeeded';

      rc=0;
      put '----';
      put 'Call SETMAP';
      CALL SETMAP('mqclientmap', 'REGISTRY', rc, 'CHAR,,50'); 
      if rc ^= 0 then do;
         put 'SETMAP: failed';
         msg = sysmsg();
         put msg;
      end;
      else put 'SETMAP: succeeded';

      parm1="calories";
      put '---- Send a message to the request queue qid 
         requesting the specified dataset -----';
      put 'Call SENDMESSAGE';
      call sendmessage(qid2,rc,"map, respqueue", 
         "mqclientmap","R64:D8650",parm1); 
      if rc ^= 0 then do;
         put 'send message failed: ';
         msg=sysmsg();
         put msg;
      end;
      else put 'send message succeeded';

      slept = sleep(1);
      rc = 0;
      put '---- receive a dataset from the reply queue ----';
      put 'Call RECEIVEMESSAGE';
      map = "mqclientmap";
      call receivemessage(qid, rc, event, 
         attchflg,"map", map, recv1); 
      put 'response queue =' rpname;
      put 'qid =' qid;
      put 'event = ' event;
      put 'attchflg =' attchflg;
      if rc ^= 0 then do;
         put 'receive message failed: ';
         msg=sysmsg();
         put msg;
      end;
      else do;
         put 'receive message succeeded';
         put "map =" map;
	     put "recv1 =" recv1;
      end;

      if event eq 'DELIVERY' then
      do;
         put 'Message has been delivered';
         if attchflg = 1 then 
	     do;
            put '---- check for attachments ----';
            call getattachment(qid, lastflag, attachid, 
               type, qual1, qual2, rc);
            if rc ^= 0 then do;
               put 'get attachment failed: ';
               msg=sysmsg();
               put msg;
               end;
            else put 'get attachment succeeded';

            if type="DATASET" then
            do;
               put '--- accept attachment into a dataset ---';
	    	    put "qual2 = " qual2;
               call acceptattachment(qid, attachid, 
                  "out", qual2, rc);
               if rc ^= 0 then do;
                  put 'accept DATASET failed: ';
                  msg=sysmsg();
                  put msg;
               end;
                  else put 'accept DATASET succeeded';
            end;
         end;
      end;

      rc=0;
      put '----';
      put 'Call CLOSEQUEUE for queue1';
      CALL CLOSEQUEUE(qid, rc);
      if rc ^= 0 then do;
         put 'CLOSEQUEUE: failed';
         msg = sysmsg();
         put msg;
      end;
      else put 'CLOSEQUEUE: succeeded';

      rc=0;
      put '----';
      put 'Call CLOSEQUEUE for queue2';
      CALL CLOSEQUEUE(qid2, rc);
      if rc ^= 0 then do;
         put 'CLOSEQUEUE: failed';
         msg = sysmsg();
         put msg;
      end;
      else put 'CLOSEQUEUE: succeeded';

      rc=0;
      put '----';
      put 'Call TERM';
      CALL TERM(tid, rc);
      if rc ^= 0 then do;
         put 'TERM: failed';
         msg = sysmsg();
         put msg;
      end;
      else put 'TERM: succeeded';

   run;

mqserver.sas

   data calories;
      input item $ 1 - 16 calories 18-20 ;
      datalines;
   ground beef      230
   hot dog          100
   banana           100
   broccoli          45
   skim milk         50
   ;


   data _null_;

      length msg $ 200;
      length qid qid2 tid rc 8;
      length map $80;
      length recv1 $50;
      length attachname $21;
      length event  $10;
      length rpname $256;
      tid=0;
      rc=0;

      put '----';
      put 'Call INIT';
      CALL INIT(tid, 'MQSERIES-C', rc);
      if rc ^= 0 then do;
         put 'INIT: failed';
         msg = sysmsg();
         put msg;
      end;
      else put 'INIT: succeeded';

      rc=0;
      qid=0;
      put '----';
      put 'Call OPENQUEUE for queue1';
      CALL OPENQUEUE(qid, tid, 'AIX:TRIGQUEUE', 
         'fetch', rc, "POLL(Timeout=10)");
      if rc ^= 0 then do;
         put 'OPENQUEUE: failed';
         msg = sysmsg();
         put msg;
      end;
      else put 'OPENQUEUE: succeeded';

      rc=0;
      put '----';
      put 'Call SETMAP';
      CALL SETMAP('mqservermap', 'REGISTRY', rc, 'CHAR,,50'); 
      if rc ^= 0 then do;
         put 'SETMAP: failed';
         msg = sysmsg();
         put msg;
      end;
      else put 'SETMAP: succeeded';

      rc = 0;
      put '---- recieve a message from the remote queue ----';
      put 'Call RECEIVEMESSAGE';

      map = "mqservermap";
      rpname=' ';
      call receivemessage(qid, rc, event, attchflg,"map, 
         respqueue", map, rpname, recv1);
      put 'recv1 =' recv1;
      put 'response queue =' rpname;
      put 'qid =' qid;
      put 'event = ' event;
      put 'attchflg =' attchflg;

      if rc ^= 0 then do;
         put 'receive message failed: ';
         msg=sysmsg();
         put msg;
      end;
      else do;
         put 'receive message succeeded';
         put map;
      end;

      if event eq 'DELIVERY' then
      do;
         rc = 0;
         qid2=0;

         put '---- open the  response queue qid2 ----';
         put 'Call OPENQUEUE for queue2';
         CALL OPENQUEUE(qid2, tid, rpname, 'delivery', 
            rc, "POLL(Timeout=15)");
         if rc ^= 0 then do;
            put 'OPENQUEUE: failed';
            msg = sysmsg();
            put msg;
         end;
         else put 'OPENQUEUE: succeeded';
         put 'rpname =' rpname;

         put '---- send the requested dataset 
            to the response queue ----';
         put 'Call SENDMESSAGE';
         attachname = 'dataset,work,' || recv1;
         put "attachname = " attachname;
         call sendmessage(qid2,rc,"map, attachlist",
            "mqservermap",attachname, recv1 ); 
         if rc ^= 0 then do;
            put 'send message failed: ';
            msg=sysmsg();
            put msg;
         end;
         else put 'send message succeeded'; 
  
         rc=0;
         put '----';
         put 'Call CLOSEQUEUE for queue2';
         CALL CLOSEQUEUE(qid2, rc);
         if rc ^= 0 then do;
            put 'CLOSEQUEUE: failed';
            msg = sysmsg();
            put msg;
         end;
         else put 'CLOSEQUEUE: succeeded';
      end;

      rc=0;
      put '----';
      put 'Call CLOSEQUEUE for queue1';
      CALL CLOSEQUEUE(qid, rc);
      if rc ^= 0 then do;
         put 'CLOSEQUEUE: failed';
         msg = sysmsg();
         put msg;
      end;
      else put 'CLOSEQUEUE: succeeded';

      rc=0;
      put '----';
      put 'Call TERM';
      CALL TERM(tid, rc);
      if rc ^= 0 then do;
         put 'TERM: failed';
         msg = sysmsg();
         put msg;
      end;
      else put 'TERM: succeeded';

   run;