(* Collection of code snippets by Arne Vajhøj *)
(* (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) *)
[inherit('common','pstomp','pjson')]
program recv(input,output);

%include 'data.inc'
%include 'datajson.inc'

var
   ctx : stomp_ctx;
   msg : pstr;
   msglen : integer;
   done : boolean;
   o : array [1..100] of order;
   i, j, n : integer;

begin
   stomp_debug(0);
   stomp_init(ctx, 'localhost', 61613);
   done := false;
   repeat
      stomp_read(ctx, 'DemoQ', msg.body, msglen);
      if msg.body[msglen] = chr(10) then msglen := msglen - 1;
      msg.length := msglen;
      if msg = 'quit' then begin
         done := true;
      end else begin
         n := parse_data(msg, o);
         for i := 1 to n do begin
            write('id=', o[i].id:1);
            write(' customer=', o[i].customer);
            writeln(' status=', o[i].status);
            for j := 1 to o[i].nlines do begin
               write('  item=', o[i].line[j].item);
               write(' qty=', o[i].line[j].qty:1);
               writeln(' price=', (o[i].line[j].price / 100.00):4:2);
            end;
         end;
      end;
   until done;
   stomp_close(ctx);
end.
