Exemple #1
0
 public void Connect(bool isAutoConnect = true)
 {
     try
     {
         _connection = RabbitMQUtils.CreateNewConnection(_serverOptions, _virtualHost);
         if (Connected != null)
         {
             Connected.Invoke(this);
         }
     }
     catch (Exception ex)
     {
         _logger.Error(ex, "The rabbit mq service cannot connect! ServerOptions: {0}", _serverOptions.ToString());
         if (isAutoConnect)
         {
             _logger.Info($"Auto connect is enable, the service will reconnect to the rabbit mq server after {_reconnectMilliSeconds} ms!");
             tryReConnect();
         }
         else
         {
             throw ex;
         }
     }
 }