I have this problem with TMS MQTT, because the library does not work properly (does not connect to the broker) when used in a console application or Windows service.
Is it supposed to be like this or am I doing something wrong?
I'm really at a loss because I purchased this library with the idea of using it to transfer messages between microservices and here is such a "surprise".
I'll admit that I didn't check it thoroughly before purchasing it and I was suggested by the fact that you strongly emphasize that everything is thread-based.
And here there is clearly a problem with the creation of working threads when trying to connect to the broker.
Of course, in the "windows" application everything works as it should.
Note: Because Synchronize uses a message loop, it does not work in console applications. For console applications, use other mechanisms, such as critical sections, to protect access to VCL objects.
And TMS MQTT simply uses the Synchornize method, and as far as I know, it has no right to work in a console application.
// Check if we need to reconnect
if (not Session.HasActiveNetworkConnection) and FShouldTryReconnect then
begin
if (IncSecond(Session.LastWriteCommunicationTime, FReconnectInterval) <= LNow) then
begin
TTMSMQTTLogHelper.Info(Log, self, 'KEEP ALIVE - No Connection. Requesting Reconnect.');
{$IFDEF CONSOLE}
FCS.Enter;
try
RequestReconnect;
finally
FCS.Leave;
end;
{$ELSE}
Synchronize(RequestReconnect);
{$ENDIF}
Session.LastWriteCommunicationTime := LNow;
end;
end;
Everything seems to work correctly, although I'm just starting more serious testing....
Can you check with the latest beta? We released an update today.
With this update, we have tested this and it works fine from a Windows service.
For use from a Windows service, please set the property SyncEvents to false.