(* Collection of code snippets by Arne Vajhøj *)
(* (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) *)
program bad2;

uses
  StompClient, StompTypes, delphistomp, laz_synapse, mqu;

type
  BadMQ = class (MQ)
  public
    function get_connection : TStompClient; override;
    procedure test; override;
  end;

function BadMQ.get_connection : TStompClient;

var
  con : TStompClient;

begin
  con := TStompClient.Create;
  con.Connect('localhost', 61613);
  get_connection := con;
end;

procedure BadMQ.test;

var
  con : TStompClient;
  fr : IStompFrame;
  i : integer;
  msg : string;

begin
  con := get_connection;
  con.Subscribe('Qin');
  for i := 1 to 10 do begin
    try
      fr := con.Receive;
      msg := fr.GetBody;
      if (i mod 2) <> 1 then begin
        raise Problem.Create('Problem');
      end;
      con.Send('Qout', msg);
    except
      writeln('Problem');
    end;
  end;
  con.Unsubscribe('Qin');
  con.Disconnect;
end;

begin
  BadMQ.demo(BadMQ.Create);
end.

