2009-11-10 11:32:54 +01:00
|
|
|
|
unit MainU;
|
|
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
2012-04-18 19:19:31 +02:00
|
|
|
|
uses
|
|
|
|
|
StompTypes;
|
|
|
|
|
|
|
|
|
|
procedure Main(serveraddress: string = 'localhost';
|
|
|
|
|
STOMP_VERSION: TStompAcceptProtocol = STOMP_Version_1_0);
|
2009-11-10 11:32:54 +01:00
|
|
|
|
procedure MainWithTransaction(serveraddress: string = 'localhost');
|
|
|
|
|
procedure Test_Unicode_Chars(serveraddress: string = 'localhost');
|
|
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
|
|
uses
|
|
|
|
|
SysUtils,
|
|
|
|
|
dateutils,
|
|
|
|
|
StompClient,
|
2010-04-02 12:44:54 +02:00
|
|
|
|
Diagnostics;
|
2009-11-10 11:32:54 +01:00
|
|
|
|
|
|
|
|
|
procedure Test_Unicode_Chars(serveraddress: string);
|
|
|
|
|
var
|
2010-04-13 12:39:09 +02:00
|
|
|
|
stomp: IStompClient;
|
2010-04-02 12:44:54 +02:00
|
|
|
|
s: IStompFrame;
|
2012-04-18 19:19:31 +02:00
|
|
|
|
utf8s: UTF8String;
|
|
|
|
|
s1: string;
|
2009-11-10 11:32:54 +01:00
|
|
|
|
const
|
|
|
|
|
SERBO = '<27>to je Unicode';
|
|
|
|
|
SVEDESE = 'Vad <20>r Unicode';
|
|
|
|
|
ITALIANO = 'Cos''<27> Unicode';
|
|
|
|
|
begin
|
2010-04-14 00:25:14 +02:00
|
|
|
|
stomp := StompUtils.NewStomp(serveraddress);
|
2010-04-13 12:39:09 +02:00
|
|
|
|
stomp.Subscribe('/topic/unicode');
|
2012-04-18 19:19:31 +02:00
|
|
|
|
|
2010-04-13 12:39:09 +02:00
|
|
|
|
stomp.Send('/topic/unicode', ITALIANO);
|
|
|
|
|
stomp.Send('/topic/unicode', SERBO);
|
|
|
|
|
stomp.Send('/topic/unicode', SVEDESE);
|
|
|
|
|
|
|
|
|
|
s := stomp.Receive;
|
|
|
|
|
assert(s <> nil);
|
2012-04-18 19:19:31 +02:00
|
|
|
|
s1 := s.GetBody;
|
2010-04-13 12:39:09 +02:00
|
|
|
|
assert(s.GetBody = ITALIANO);
|
|
|
|
|
|
|
|
|
|
s := stomp.Receive;
|
|
|
|
|
assert(s <> nil);
|
2012-04-18 19:19:31 +02:00
|
|
|
|
s1 := s.GetBody;
|
2010-04-13 12:39:09 +02:00
|
|
|
|
assert(s.GetBody = SERBO);
|
|
|
|
|
|
|
|
|
|
s := stomp.Receive;
|
|
|
|
|
assert(s <> nil);
|
2012-04-18 19:19:31 +02:00
|
|
|
|
s1 := s.GetBody;
|
2010-04-13 12:39:09 +02:00
|
|
|
|
assert(s.GetBody = SVEDESE);
|
2009-11-10 11:32:54 +01:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure MainWithTransaction(serveraddress: string);
|
|
|
|
|
var
|
2010-04-13 12:39:09 +02:00
|
|
|
|
stomp, recv: IStompClient;
|
2010-04-02 12:44:54 +02:00
|
|
|
|
frame: IStompFrame;
|
2012-04-18 19:19:31 +02:00
|
|
|
|
s1: string;
|
2009-11-10 11:32:54 +01:00
|
|
|
|
const
|
|
|
|
|
TR = 'TRDANIELE';
|
|
|
|
|
TOPIC = '/topic/mytopic'; // TOPIC = PUB/SUB, QUEUE = LOAD BALANCER
|
|
|
|
|
BODY1 = 'Hello World 1';
|
|
|
|
|
BODY2 = 'Hello World 2';
|
|
|
|
|
BODY3 = 'Hello World 3';
|
|
|
|
|
BODY4 = 'Hello World 4';
|
|
|
|
|
begin
|
2010-04-14 00:25:14 +02:00
|
|
|
|
stomp := StompUtils.NewStomp;
|
|
|
|
|
recv := StompUtils.NewStomp;
|
2010-04-13 12:39:09 +02:00
|
|
|
|
|
|
|
|
|
stomp.Subscribe(TOPIC);
|
|
|
|
|
recv.Subscribe(TOPIC);
|
|
|
|
|
|
|
|
|
|
stomp.BeginTransaction(TR);
|
|
|
|
|
stomp.Send(TOPIC, BODY1, TR);
|
|
|
|
|
stomp.Send(TOPIC, BODY2, TR);
|
|
|
|
|
stomp.Send(TOPIC, BODY3, TR);
|
|
|
|
|
stomp.Send(TOPIC, BODY4, TR);
|
|
|
|
|
|
2012-04-18 19:19:31 +02:00
|
|
|
|
// NON DEVE TROVARE NULLA
|
2010-04-13 12:39:09 +02:00
|
|
|
|
frame := recv.Receive;
|
|
|
|
|
assert(frame = nil);
|
|
|
|
|
stomp.CommitTransaction(TR);
|
|
|
|
|
|
|
|
|
|
frame := recv.Receive;
|
|
|
|
|
assert(frame <> nil);
|
2012-04-18 19:19:31 +02:00
|
|
|
|
s1 := frame.GetBody;
|
|
|
|
|
// assert(frame.GetBody = BODY1, frame.GetBody);
|
2010-04-13 12:39:09 +02:00
|
|
|
|
|
|
|
|
|
frame := recv.Receive;
|
|
|
|
|
assert(frame <> nil);
|
2012-04-18 19:19:31 +02:00
|
|
|
|
s1 := frame.GetBody;
|
|
|
|
|
// assert(frame.GetBody = BODY2, frame.GetBody);
|
2010-04-13 12:39:09 +02:00
|
|
|
|
|
|
|
|
|
frame := recv.Receive;
|
|
|
|
|
assert(frame <> nil);
|
2012-04-18 19:19:31 +02:00
|
|
|
|
s1 := frame.GetBody;
|
|
|
|
|
// assert(frame.GetBody = BODY3);
|
2010-04-13 12:39:09 +02:00
|
|
|
|
|
|
|
|
|
frame := recv.Receive;
|
|
|
|
|
assert(frame <> nil);
|
2012-04-18 19:19:31 +02:00
|
|
|
|
s1 := frame.GetBody;
|
|
|
|
|
// assert(frame.GetBody = BODY4);
|
2010-04-13 12:39:09 +02:00
|
|
|
|
|
|
|
|
|
frame := recv.Receive;
|
|
|
|
|
assert(frame = nil);
|
2009-11-10 11:32:54 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2012-04-18 19:19:31 +02:00
|
|
|
|
procedure Main(serveraddress: string = 'localhost';
|
|
|
|
|
STOMP_VERSION: TStompAcceptProtocol = STOMP_Version_1_0);
|
2009-11-10 11:32:54 +01:00
|
|
|
|
var
|
2010-04-14 00:25:14 +02:00
|
|
|
|
stomp: IStompClient;
|
2010-04-02 12:44:54 +02:00
|
|
|
|
frame: IStompFrame;
|
2009-11-10 11:32:54 +01:00
|
|
|
|
i, c: Integer;
|
|
|
|
|
msgcount: Cardinal;
|
2010-04-14 00:25:14 +02:00
|
|
|
|
sw, sw1: TStopWatch;
|
2009-11-10 11:32:54 +01:00
|
|
|
|
message_data: string;
|
2012-04-18 19:19:31 +02:00
|
|
|
|
s1: string;
|
2009-11-10 11:32:54 +01:00
|
|
|
|
const
|
2010-04-14 00:25:14 +02:00
|
|
|
|
MSG = 5000;
|
2012-04-18 19:19:31 +02:00
|
|
|
|
MSG_SIZE = 1024 * 5; // div 10;
|
2009-11-10 11:32:54 +01:00
|
|
|
|
begin
|
2010-04-14 00:25:14 +02:00
|
|
|
|
sw1 := TStopWatch.StartNew;
|
2009-11-10 11:32:54 +01:00
|
|
|
|
message_data := StringOfChar('X', MSG_SIZE);
|
2012-04-18 19:19:31 +02:00
|
|
|
|
WriteLn('TEST MESSAGE IS (', length(message_data), ' bytes - WILL BE UTF8 Encoded):', #13#10, '"',
|
2010-04-13 12:39:09 +02:00
|
|
|
|
message_data, '"'#13#10#13#10);
|
2012-04-18 19:19:31 +02:00
|
|
|
|
stomp := StompUtils.NewStomp(serveraddress, DEFAULT_STOMP_PORT, '', 'Daniele', 'Teti',
|
|
|
|
|
STOMP_VERSION);
|
|
|
|
|
WriteLn('SERVER: ', stomp.GetServer, ' PROTOCOL VERSION: ' + stomp.GetProtocolVersion);
|
|
|
|
|
|
|
|
|
|
if STOMP_VERSION = STOMP_Version_1_1 then
|
|
|
|
|
// Include the required ID header for STOMP 1.1
|
|
|
|
|
stomp.Subscribe('/topic/foo.bar', amAuto, StompUtils.NewHeaders.Add('id', '1234'))
|
|
|
|
|
else
|
|
|
|
|
// Do not include ID header because is not required for STOMP 1.0
|
|
|
|
|
stomp.Subscribe('/topic/foo.bar', amAuto);
|
2010-04-14 00:25:14 +02:00
|
|
|
|
|
|
|
|
|
for c := 1 to 6 do
|
|
|
|
|
begin
|
|
|
|
|
WriteLn;
|
|
|
|
|
WriteLn('= STATS LOOP ', c, '=======================================');
|
|
|
|
|
sw := TStopWatch.StartNew;
|
|
|
|
|
for i := 1 to MSG do
|
2012-04-18 19:19:31 +02:00
|
|
|
|
begin
|
2010-04-14 00:25:14 +02:00
|
|
|
|
stomp.Send('/topic/foo.bar', message_data,
|
|
|
|
|
StompUtils.NewHeaders.Add(TStompHeaders.NewPersistentHeader(true)));
|
2012-04-18 19:19:31 +02:00
|
|
|
|
if i mod 100 = 0 then
|
|
|
|
|
WriteLn('Queued ', i, ' messages in ', sw.ElapsedMilliseconds, ' ms');
|
|
|
|
|
end;
|
|
|
|
|
WriteLn('Finished Queueing... Currently Queued ', MSG, ' messages in ',
|
|
|
|
|
sw.ElapsedMilliseconds, ' ms');
|
2010-04-14 00:25:14 +02:00
|
|
|
|
WriteLn('Now dequeuing...');
|
|
|
|
|
|
|
|
|
|
msgcount := 0;
|
|
|
|
|
sw := TStopWatch.StartNew;
|
|
|
|
|
while msgcount < MSG do
|
2010-04-02 12:44:54 +02:00
|
|
|
|
begin
|
2010-04-14 00:25:14 +02:00
|
|
|
|
frame := stomp.Receive;
|
|
|
|
|
if assigned(frame) then
|
2009-11-10 11:32:54 +01:00
|
|
|
|
begin
|
2010-04-14 00:25:14 +02:00
|
|
|
|
inc(msgcount);
|
2012-04-18 19:19:31 +02:00
|
|
|
|
s1 := frame.GetBody;
|
2010-04-14 00:25:14 +02:00
|
|
|
|
assert(frame.GetBody = message_data);
|
|
|
|
|
frame := nil;
|
2012-04-18 19:19:31 +02:00
|
|
|
|
if msgcount mod 100 = 0 then
|
|
|
|
|
WriteLn('DeQueued ', msgcount, ' messages in ', sw.ElapsedMilliseconds, ' ms');
|
2010-04-14 00:25:14 +02:00
|
|
|
|
end
|
2009-11-10 11:32:54 +01:00
|
|
|
|
end;
|
2010-04-14 00:25:14 +02:00
|
|
|
|
sw.Stop;
|
|
|
|
|
WriteLn('Dequeued ', msgcount, ' stomp messages in ', sw.ElapsedMilliseconds, ' ms');
|
|
|
|
|
WriteLn('Throughput: ',
|
|
|
|
|
FormatFloat('###,##0.000', sw.ElapsedMilliseconds / msgcount), ' ms/msg (',
|
|
|
|
|
FormatFloat('###,##0.000', msgcount / sw.ElapsedMilliseconds), ' msg/ms)');
|
|
|
|
|
// WriteLn('= END LOOP ', c, '========================================='#13#10);
|
2009-11-10 11:32:54 +01:00
|
|
|
|
end;
|
2010-04-14 00:25:14 +02:00
|
|
|
|
stomp.Unsubscribe('/topic/foo.bar');
|
|
|
|
|
stomp.Disconnect;
|
|
|
|
|
sw.Stop;
|
|
|
|
|
WriteLn('SPEED TEST FINISHED IN ', FormatFloat('###,##0.000', sw1.ElapsedMilliseconds / 1000),
|
|
|
|
|
' seconds');
|
2009-11-10 11:32:54 +01:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
end.
|