mirror of
https://github.com/danieleteti/delphimvcframework.git
synced 2024-11-18 01:05:54 +01:00
53 lines
1.2 KiB
ObjectPascal
53 lines
1.2 KiB
ObjectPascal
program queue_messaging_producer;
|
|
|
|
{$APPTYPE CONSOLE}
|
|
{$R *.res}
|
|
|
|
uses
|
|
System.SysUtils, MVCFramework.RESTClient, System.JSON, MVCFramework.Commons,
|
|
Winapi.Windows;
|
|
|
|
procedure Main;
|
|
var
|
|
LCli: TRESTClient;
|
|
LRes: IRESTResponse;
|
|
LMsg: TJSONObject;
|
|
LStrMsg, LMyClientID: string;
|
|
begin
|
|
{
|
|
USAGE PATTERN
|
|
POST /messages/clients/<myuniqueid>
|
|
POST /messages/queues/<queuename1> (message in the request body as json object)
|
|
}
|
|
|
|
LMyClientID := 'my-unique-client-id';
|
|
LCli := TRESTClient.Create('localhost', 9999);
|
|
try
|
|
LCli.ReadTimeout := - 1;
|
|
LRes := LCli.doPOST('/messages', ['clients', LMyClientID]);
|
|
LStrMsg := 'FIRST MESSAGE';
|
|
while True do
|
|
begin
|
|
LMsg := TJSONObject.Create(TJSONPair.Create('msg', LStrMsg)); // ;;GetTickCount.ToString));
|
|
WriteLn('Writing on the queue: ' + LMsg.ToJSON);
|
|
LRes := LCli.doPOST('/messages', ['queue', 'queue1'], LMsg);
|
|
WriteLn(LRes.ResponseCode, LRes.ResponseText);
|
|
write('Send Message: ');
|
|
ReadLn(LStrMsg);
|
|
end;
|
|
finally
|
|
LCli.Free;
|
|
end;
|
|
end;
|
|
|
|
begin
|
|
try
|
|
Main;
|
|
except
|
|
on E: Exception do
|
|
WriteLn(E.ClassName, ': ', E.Message);
|
|
end;
|
|
ReadLn;
|
|
|
|
end.
|