Delphi native implementation of a NATS Client Library. This library supports Core NATS, JetStream is currently under implementation.
...todouses
Nats.Consts,
Nats.Entities,
Nats.Connection;
// Create a connection object
LConnection := TNatsConnection.Create;
// Connect to a NATS Server
LConnection.SetChannel('localhost', 4222, 1000).
Open(
procedure (AInfo: TNatsServerInfo; var AConnectOptions: TNatsConnectOptions)
begin
TThread.Queue(TThread.Current,
procedure
begin
Log('Connected to server ' + AInfo.server_name);
end
);
end,
procedure
begin
TThread.Queue(TThread.Current,
procedure
begin
Log('Disconnected from the server');
end
);
end
)
;LConnection.Publish('mysubject', 'My Message');LConnection.Subscribe('mysubject',
procedure (const AMsg: TNatsArgsMSG)
begin
// Code to handle received Msg with subject "mysubject"
// ** Remember! your code here must be thread safe!
Log('Message received from NATS server: ' + AMsg);
end
); LConnection.Unsubscribe('mysubject');JetStream is the built-in NATS persistence system. nats.delphi provides a built-in
API enabling both managing JetStream assets as well as publishing/consuming
persistent messages.
JetStream support is under active development.
