Esempio n. 1
0
        async Task <MessagingFactoryContext> CreateConnection(ISupervisor supervisor)
        {
            try
            {
                if (supervisor.Stopping.IsCancellationRequested)
                {
                    throw new OperationCanceledException($"The connection is stopping and cannot be used: {_serviceUri}");
                }

                var messagingFactory = await MessagingFactory.CreateAsync(_serviceUri, _messagingFactorySettings).ConfigureAwait(false);

                messagingFactory.RetryPolicy = _retryPolicy;

                LogContext.Debug?.Log("Connected: {Host}", _serviceUri);

                var messagingFactoryContext = new ServiceBusMessagingFactoryContext(messagingFactory, supervisor.Stopped);

                return(messagingFactoryContext);
            }
            catch (Exception ex)
            {
                LogContext.Error?.Log(ex, "Connect failed: {Host}", _serviceUri);

                throw;
            }
        }
Esempio n. 2
0
        async Task <MessagingFactoryContext> CreateConnection(ISupervisor supervisor)
        {
            try
            {
                if (supervisor.Stopping.IsCancellationRequested)
                {
                    throw new OperationCanceledException($"The connection is stopping and cannot be used: {_serviceUri}");
                }

                if (_log.IsDebugEnabled)
                {
                    _log.DebugFormat("Connecting: {0}", _serviceUri);
                }

                var messagingFactory = await MessagingFactory.CreateAsync(_serviceUri, _messagingFactorySettings).ConfigureAwait(false);

                messagingFactory.RetryPolicy = _retryPolicy;

                if (_log.IsDebugEnabled)
                {
                    _log.DebugFormat("Connected: {0}", _serviceUri);
                }

                var messagingFactoryContext = new ServiceBusMessagingFactoryContext(messagingFactory, supervisor.Stopped);

                return(messagingFactoryContext);
            }
            catch (Exception ex)
            {
                if (_log.IsDebugEnabled)
                {
                    _log.Debug($"MessagingFactory Create Failed: {_serviceUri}", ex);
                }

                throw;
            }
        }