2012-04-18 19:19:31 +02:00
|
|
|
unit MainForm;
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
Winapi.Windows,
|
|
|
|
Winapi.Messages,
|
|
|
|
System.SysUtils,
|
|
|
|
System.Variants,
|
|
|
|
System.Classes,
|
|
|
|
Vcl.Graphics,
|
|
|
|
Vcl.Controls,
|
|
|
|
Vcl.Forms,
|
|
|
|
Vcl.Dialogs,
|
|
|
|
Vcl.StdCtrls,
|
|
|
|
StompTypes;
|
|
|
|
|
|
|
|
type
|
|
|
|
TForm4 = class(TForm, IStompClientListener)
|
|
|
|
Button1: TButton;
|
|
|
|
Memo1: TMemo;
|
2016-10-14 15:19:06 +02:00
|
|
|
Button2: TButton;
|
|
|
|
Button3: TButton;
|
2012-04-18 19:19:31 +02:00
|
|
|
procedure Button1Click(Sender: TObject);
|
2016-10-14 15:19:06 +02:00
|
|
|
procedure FormDestroy(Sender: TObject);
|
|
|
|
procedure FormCreate(Sender: TObject);
|
|
|
|
procedure Button2Click(Sender: TObject);
|
|
|
|
procedure Button3Click(Sender: TObject);
|
2012-04-18 19:19:31 +02:00
|
|
|
private
|
2016-10-14 15:19:06 +02:00
|
|
|
FSTOMPListener: IStompListener;
|
|
|
|
FSTOMPClient: IStompClient;
|
|
|
|
FFormClosing: Boolean;
|
|
|
|
FProducerThread: TThread;
|
2012-04-18 19:19:31 +02:00
|
|
|
public
|
2016-10-14 15:19:06 +02:00
|
|
|
procedure OnMessage(MessageBody: string; var TerminateListener: Boolean);
|
|
|
|
procedure OnListenerStopped(StompClient: IStompClient);
|
2012-04-18 19:19:31 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
var
|
|
|
|
Form4: TForm4;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
uses StompClient;
|
|
|
|
|
|
|
|
{$R *.dfm}
|
|
|
|
|
|
|
|
|
|
|
|
procedure TForm4.Button1Click(Sender: TObject);
|
|
|
|
begin
|
2016-10-14 15:19:06 +02:00
|
|
|
FSTOMPListener.StopListening;
|
|
|
|
FSTOMPListener.StartListening;
|
|
|
|
end;
|
2012-04-18 19:19:31 +02:00
|
|
|
|
2016-10-14 15:19:06 +02:00
|
|
|
procedure TForm4.Button2Click(Sender: TObject);
|
|
|
|
begin
|
|
|
|
FSTOMPListener.StopListening;
|
|
|
|
end;
|
2012-04-18 19:19:31 +02:00
|
|
|
|
2016-10-14 15:19:06 +02:00
|
|
|
procedure TForm4.Button3Click(Sender: TObject);
|
|
|
|
begin
|
|
|
|
FProducerThread := TThread.CreateAnonymousThread(
|
2016-09-20 16:27:17 +02:00
|
|
|
procedure
|
2012-04-18 19:19:31 +02:00
|
|
|
var
|
|
|
|
i: Integer;
|
|
|
|
stomp: IStompClient;
|
|
|
|
begin
|
2016-09-20 16:27:17 +02:00
|
|
|
stomp := TStompClient.CreateAndConnect;
|
2016-10-14 15:19:06 +02:00
|
|
|
i := 1;
|
|
|
|
while True do
|
2012-04-18 19:19:31 +02:00
|
|
|
begin
|
2016-10-14 15:19:06 +02:00
|
|
|
sleep(300);
|
|
|
|
if FFormClosing then
|
|
|
|
Exit;
|
2016-09-20 16:27:17 +02:00
|
|
|
stomp.Send('/topic/danieleteti', 'Hello World ' + IntToStr(i));
|
2016-10-14 15:19:06 +02:00
|
|
|
inc(i);
|
2012-04-18 19:19:31 +02:00
|
|
|
end;
|
|
|
|
stomp.Disconnect;
|
2016-10-14 15:19:06 +02:00
|
|
|
end);
|
|
|
|
FProducerThread.FreeOnTerminate := False;
|
|
|
|
FProducerThread.Start;
|
2012-04-18 19:19:31 +02:00
|
|
|
end;
|
|
|
|
|
2016-10-14 15:19:06 +02:00
|
|
|
procedure TForm4.FormCreate(Sender: TObject);
|
2012-04-18 19:19:31 +02:00
|
|
|
begin
|
2016-10-14 15:19:06 +02:00
|
|
|
FFormClosing := False;
|
|
|
|
FSTOMPClient := TStompClient.CreateAndConnect;
|
|
|
|
FSTOMPClient.Subscribe('/topic/danieleteti',
|
|
|
|
amAuto,
|
|
|
|
StompUtils.Headers.Add('include-seq', 'seq'));
|
|
|
|
FSTOMPListener := TStompClientListener.Create(FSTOMPClient, Self);
|
2012-04-18 19:19:31 +02:00
|
|
|
end;
|
|
|
|
|
2016-10-14 15:19:06 +02:00
|
|
|
procedure TForm4.FormDestroy(Sender: TObject);
|
2012-04-18 19:19:31 +02:00
|
|
|
begin
|
2016-10-14 15:19:06 +02:00
|
|
|
FFormClosing := True;
|
|
|
|
FProducerThread.WaitFor;
|
|
|
|
FProducerThread.Free;
|
|
|
|
FSTOMPListener := nil;
|
2012-04-18 19:19:31 +02:00
|
|
|
end;
|
|
|
|
|
2016-10-14 15:19:06 +02:00
|
|
|
procedure TForm4.OnMessage(MessageBody: string; var TerminateListener: Boolean);
|
2012-04-18 19:19:31 +02:00
|
|
|
begin
|
2016-10-14 15:19:06 +02:00
|
|
|
Memo1.Lines.Add(MessageBody);
|
|
|
|
TerminateListener := FFormClosing;
|
2012-04-18 19:19:31 +02:00
|
|
|
end;
|
|
|
|
|
2016-10-14 15:19:06 +02:00
|
|
|
procedure TForm4.OnListenerStopped(StompClient: IStompClient);
|
2012-04-18 19:19:31 +02:00
|
|
|
begin
|
2016-10-14 15:19:06 +02:00
|
|
|
Memo1.Lines.Add('Listener Stopped');
|
2012-04-18 19:19:31 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
initialization
|
|
|
|
|
|
|
|
AllocConsole;
|
|
|
|
|
|
|
|
end.
|