2012-12-27 23:32:04 +01:00
|
|
|
unit ReceiverForm;
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
2016-01-01 23:14:46 +01:00
|
|
|
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
|
|
|
|
System.Classes, Vcl.Graphics,
|
2012-12-27 23:32:04 +01:00
|
|
|
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, StompClient, StompTypes,
|
|
|
|
ThreadReceiver;
|
|
|
|
|
|
|
|
type
|
|
|
|
TReceiverMainForm = class(TForm)
|
|
|
|
MessageMemo: TMemo;
|
|
|
|
Label1: TLabel;
|
|
|
|
SubscribeButton: TButton;
|
|
|
|
QueueEdit: TEdit;
|
|
|
|
Label2: TLabel;
|
|
|
|
SendAckButton: TButton;
|
|
|
|
SendNackButton: TButton;
|
|
|
|
Label3: TLabel;
|
|
|
|
UnsubscribeButton: TButton;
|
|
|
|
MessageIdEdit: TEdit;
|
|
|
|
Label4: TLabel;
|
|
|
|
LogMemo: TMemo;
|
|
|
|
Label5: TLabel;
|
|
|
|
procedure SubscribeButtonClick(Sender: TObject);
|
|
|
|
procedure FormCreate(Sender: TObject);
|
|
|
|
procedure SendNackButtonClick(Sender: TObject);
|
|
|
|
procedure SendAckButtonClick(Sender: TObject);
|
|
|
|
procedure UnsubscribeButtonClick(Sender: TObject);
|
|
|
|
procedure FormDestroy(Sender: TObject);
|
|
|
|
private
|
|
|
|
StompClient: TStompClient;
|
|
|
|
StompFrame: IStompFrame;
|
|
|
|
ThReceiver: TThreadReceiver;
|
|
|
|
procedure BeforeSendFrame(AFrame: IStompFrame);
|
|
|
|
public
|
|
|
|
end;
|
|
|
|
|
|
|
|
var
|
|
|
|
ReceiverMainForm: TReceiverMainForm;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
{$R *.dfm}
|
|
|
|
|
2016-08-02 18:15:11 +02:00
|
|
|
|
2012-12-27 23:32:04 +01:00
|
|
|
procedure TReceiverMainForm.BeforeSendFrame(AFrame: IStompFrame);
|
|
|
|
begin
|
2016-08-02 18:15:11 +02:00
|
|
|
LogMemo.Lines.Add(StringReplace(AFrame.Output, #10, sLineBreak, [rfReplaceAll]));
|
2012-12-27 23:32:04 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TReceiverMainForm.FormCreate(Sender: TObject);
|
|
|
|
begin
|
|
|
|
StompClient := TStompClient.Create;
|
|
|
|
try
|
|
|
|
StompClient.Connect;
|
|
|
|
except
|
2016-08-02 18:15:11 +02:00
|
|
|
on e: Exception do
|
2012-12-27 23:32:04 +01:00
|
|
|
begin
|
2016-08-02 18:15:11 +02:00
|
|
|
raise Exception.Create
|
2016-01-01 23:14:46 +01:00
|
|
|
('Cannot connect to Apollo server. Run the server and restart the application');
|
2012-12-27 23:32:04 +01:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
StompClient.OnBeforeSendFrame := BeforeSendFrame;
|
|
|
|
StompFrame := StompUtils.NewFrame();
|
|
|
|
ThReceiver := TThreadReceiver.Create(True);
|
|
|
|
ThReceiver.StompClient := StompClient;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TReceiverMainForm.FormDestroy(Sender: TObject);
|
|
|
|
begin
|
|
|
|
ThReceiver.Free;
|
|
|
|
StompClient.Free;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TReceiverMainForm.SendAckButtonClick(Sender: TObject);
|
|
|
|
begin
|
2016-01-01 23:14:46 +01:00
|
|
|
if MessageIdEdit.Text = '' then
|
2016-08-02 18:15:11 +02:00
|
|
|
raise Exception.Create('Specify MessageId');
|
2012-12-27 23:32:04 +01:00
|
|
|
|
|
|
|
if StompClient.Connected then
|
|
|
|
begin
|
|
|
|
StompClient.Ack(MessageIdEdit.Text);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TReceiverMainForm.SendNackButtonClick(Sender: TObject);
|
|
|
|
begin
|
2016-01-01 23:14:46 +01:00
|
|
|
if MessageIdEdit.Text = '' then
|
2016-08-02 18:15:11 +02:00
|
|
|
raise Exception.Create('Specify MessageId');
|
2012-12-27 23:32:04 +01:00
|
|
|
|
|
|
|
if StompClient.Connected then
|
|
|
|
begin
|
|
|
|
StompClient.Nack(MessageIdEdit.Text);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TReceiverMainForm.SubscribeButtonClick(Sender: TObject);
|
2016-08-02 18:15:11 +02:00
|
|
|
var
|
|
|
|
lAuto: Boolean;
|
|
|
|
lAckMode: TAckMode;
|
2012-12-27 23:32:04 +01:00
|
|
|
begin
|
2016-08-02 18:15:11 +02:00
|
|
|
if not StompClient.Connected then
|
|
|
|
raise Exception.Create('StompClient not connected');
|
|
|
|
|
2016-01-01 23:14:46 +01:00
|
|
|
if QueueEdit.Text = '' then
|
2016-08-02 18:15:11 +02:00
|
|
|
raise Exception.Create('Specify queue name');
|
2012-12-27 23:32:04 +01:00
|
|
|
|
2016-08-02 18:15:11 +02:00
|
|
|
lAuto := MessageDlg('AckMode AUTO (Yes) or CLIENT (No) ?', mtInformation, mbYesNo, 0) = mrYes;
|
|
|
|
|
|
|
|
if lAuto then
|
|
|
|
lAckMode := amAuto
|
|
|
|
else
|
|
|
|
lAckMode := amClient;
|
|
|
|
|
|
|
|
StompClient.Subscribe(QueueEdit.Text, lAckMode);
|
|
|
|
// StompClient.Subscribe(QueueEdit.Text,amAuto);
|
|
|
|
if not ThReceiver.Started then
|
2016-01-01 23:14:46 +01:00
|
|
|
ThReceiver.Start;
|
2012-12-27 23:32:04 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TReceiverMainForm.UnsubscribeButtonClick(Sender: TObject);
|
|
|
|
begin
|
2016-01-01 23:14:46 +01:00
|
|
|
if QueueEdit.Text = '' then
|
2016-08-02 18:15:11 +02:00
|
|
|
raise Exception.Create('Specify queue name');
|
2012-12-27 23:32:04 +01:00
|
|
|
|
|
|
|
if StompClient.Connected then
|
|
|
|
begin
|
|
|
|
StompClient.Unsubscribe(QueueEdit.Text);
|
2016-08-02 18:15:11 +02:00
|
|
|
// ThReceiver.Start;
|
2012-12-27 23:32:04 +01:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|