public void TestRetry() { var connectionFactory = new Mock <RC.IConnectionFactory>(); var connection = new Mock <RC.IConnection>(); connection.Setup(c => c.IsOpen).Returns(true); connectionFactory.Setup((f) => f.CreateConnection(It.IsAny <string>())).Returns(connection.Object); var channel1 = new Mock <RC.IModel>(); channel1.Setup(c => c.IsOpen).Returns(true); connection.Setup(c => c.CreateModel()).Returns(channel1.Object); channel1.Setup((c) => c.QueueDeclare(It.IsAny <string>(), It.IsAny <bool>(), It.IsAny <bool>(), It.IsAny <bool>(), It.IsAny <IDictionary <string, object> >())).Throws <Exception>(); var ccf = new CachingConnectionFactory(connectionFactory.Object); var rtt = new PollyRetryTemplate(new Dictionary <Type, bool>(), 3, true, 1, 1, 1); var serviceCollection = CreateContainer(); serviceCollection.AddSingleton <IConnectionFactory>(ccf); serviceCollection.AddRabbitAdmin((p, a) => { a.RetryTemplate = rtt; }); var foo = new Config.AnonymousQueue("foo"); serviceCollection.AddRabbitQueue(foo); var provider = serviceCollection.BuildServiceProvider(); var admin = provider.GetRabbitAdmin(); Assert.Throws <RabbitUncategorizedException>(() => ccf.CreateConnection()); channel1.Verify((c) => c.QueueDeclare(It.IsAny <string>(), It.IsAny <bool>(), It.IsAny <bool>(), It.IsAny <bool>(), It.IsAny <IDictionary <string, object> >()), Times.Exactly(3)); }
private void DoInitialize() { lock (_lifecycleMonitor) { if (IsRunning || !IsAutoStartup) { return; } if (RetryTemplate == null && !RetryDisabled) { RetryTemplate = new PollyRetryTemplate(new Dictionary <Type, bool>(), DECLARE_MAX_ATTEMPTS, true, DECLARE_INITIAL_RETRY_INTERVAL, DECLARE_MAX_RETRY_INTERVAL, DECLARE_RETRY_MULTIPLIER, _logger); } if (ConnectionFactory is CachingConnectionFactory && ((CachingConnectionFactory)ConnectionFactory).CacheMode == CachingMode.CONNECTION) { _logger?.LogWarning("RabbitAdmin auto declaration is not supported with CacheMode.CONNECTION"); return; } ConnectionFactory.AddConnectionListener(this); IsRunning = true; } }