mirror of
https://github.com/danieleteti/delphimvcframework.git
synced 2024-11-16 16:25:54 +01:00
60 lines
1.3 KiB
ObjectPascal
60 lines
1.3 KiB
ObjectPascal
|
program consumer;
|
||
|
|
||
|
{$APPTYPE CONSOLE}
|
||
|
|
||
|
{$R *.res}
|
||
|
|
||
|
{
|
||
|
https://www.rabbitmq.com/tutorials/tutorial-two-python.html
|
||
|
}
|
||
|
|
||
|
uses
|
||
|
System.SysUtils, StompClient, StompTypes;
|
||
|
|
||
|
procedure Main;
|
||
|
var
|
||
|
lClient: TStompClient;
|
||
|
lStompFrame: IStompFrame;
|
||
|
lMessage: string;
|
||
|
begin
|
||
|
lClient := TStompClient.Create;
|
||
|
lClient.Connect();
|
||
|
WriteLn('Subscribing to queue "myjobqueue"');
|
||
|
lClient.Subscribe('myjobqueue', TAckMode.amClient);
|
||
|
|
||
|
while true do
|
||
|
begin
|
||
|
WriteLn(sLineBreak + 'Waiting for messages... (KILL program to exit)' + sLineBreak +
|
||
|
StringOfChar('*', 40));
|
||
|
|
||
|
if lClient.Receive(lStompFrame, 5000) then
|
||
|
begin
|
||
|
lMessage := lStompFrame.GetBody;
|
||
|
WriteLn(Format('Got message [%s]. Please wait, I''m working on it...', [lMessage]));
|
||
|
Sleep(1000 * lMessage.CountChar('.'));
|
||
|
WriteLn(lMessage);
|
||
|
WriteLn('Informing the broker that the message ' + lStompFrame.MessageID +
|
||
|
' has been properly processed');
|
||
|
lClient.Ack(lStompFrame.MessageID);
|
||
|
end
|
||
|
else
|
||
|
WriteLn('Cannot read message after timeout...');
|
||
|
end;
|
||
|
lClient.Disconnect;
|
||
|
end;
|
||
|
|
||
|
begin
|
||
|
try
|
||
|
Main;
|
||
|
Write('Press return to quit');
|
||
|
ReadLn;
|
||
|
except
|
||
|
on E: Exception do
|
||
|
begin
|
||
|
WriteLn(E.ClassName, ': ', E.Message);
|
||
|
ReadLn;
|
||
|
end;
|
||
|
end;
|
||
|
|
||
|
end.
|