Put try-catch statement when trying to connect to the queue for the first time

This commit is contained in:
Noe 2023-11-06 14:29:04 +01:00
parent 30a3a05de0
commit 511c3080a6
1 changed files with 15 additions and 8 deletions

View File

@ -298,14 +298,21 @@ internal static class Program
private static void SubscribeToQueue(SalimaxAlarmState currentSalimaxState, String? s3Bucket)
{
_factory = new ConnectionFactory { HostName = VpnServerIp };
_connection = _factory.CreateConnection();
_channel = _connection.CreateModel();
_channel.QueueDeclare(queue: "statusQueue", durable: false, exclusive: false, autoDelete: false, arguments: null);
Console.WriteLine("The controller sends its status to the middleware for the first time");
if (s3Bucket != null) InformMiddleware(s3Bucket, (Int32)currentSalimaxState);
try
{
_factory = new ConnectionFactory { HostName = VpnServerIp };
_connection = _factory.CreateConnection();
_channel = _connection.CreateModel();
_channel.QueueDeclare(queue: "statusQueue", durable: false, exclusive: false, autoDelete: false, arguments: null);
Console.WriteLine("The controller sends its status to the middleware for the first time");
if (s3Bucket != null) InformMiddleware(s3Bucket, (Int32)currentSalimaxState);
_subscribedToQueue = true;
_subscribedToQueue = true;
}
catch (Exception ex)
{
Console.WriteLine("An error occurred while connecting to the RabbitMQ queue: " + ex.Message);
}
}
private static IPAddress FindVpnIp()