Previous Page | Next Page

Using the SAS Common Messaging Interface

TIB/Rendezvous Coding Example

The following example of a SAS DATA step shows how to use the SAS Common Messaging Interface with the TIB/Rendezvous transport to send and receive messages using subject-based addressing.

   data _null_;

   length msg $ 200;
   length qid qid2 tid rc attchflg 8;
   length parm1 parm2 parm3 recv1 recv2 recv3 8;
   length parm4 recv4 $50;
   length map $ 80;
   length event $ 10;

   tid=0;
   rc=0;
   put '----';
   put 'Call INIT';
   CALL INIT(tid, 'RENDEZVOUS', 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 to listen 
      for and receive messages';
   CALL OPENQUEUE(qid, tid, 'test.subject', 
      'FETCH', rc, "POLL(Timeout=15)");
   if rc ^= 0 then do;
      put 'OPENQUEUE: failed';
      msg = sysmsg();
      put msg;
   end;
   else put 'OPENQUEUE: succeeded';

   rc=0;
   qid2=0;
   put '----';
   put 'Call OPENQUEUE for queue2 to send messages';
   CALL OPENQUEUE(qid2, tid, 'test.subject', 
      'DELIVERY', rc);
   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('mymap', 'REGISTRY', rc, 
      'SHORT;LONG;DOUBLE;CHAR,,50'); 
   if rc ^= 0 then do;
      put 'SETMAP: failed';
      msg = sysmsg();
      put msg;
   end;
   else put 'SETMAP: succeeded';

   parm1=100;
   parm2=9999;
   parm3=9999.1234;
   parm4="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

   put '----';
   put 'Call SENDMESSAGE';
   call sendmessage(qid2,rc,"map","mymap" ,
      parm1,parm2,parm3,parm4); 
   if rc ^= 0 then do;
      put 'send message failed: ';
      msg=sysmsg();
      put msg;
   end;
   else put 'send message succeeded';
   
   rc = 0;
   put '----';
   put 'Call RECEIVEMESSAGE';

   map = "mymap";
   call receivemessage(qid, rc, event, 
      attchflg,"map",map,recv1,recv2,recv3,recv4); 
   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;
      put 'Message has been delivered';
      put 'recv1 = ' recv1;
      put 'recv2 = ' recv2;
      put 'recv3 = ' recv3; 
      put 'recv4 = ' recv4;
   end; 

   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 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;

Previous Page | Next Page | Top of Page