/// <summary>Does the test.</summary> /// <param name="concurrentConsumers">The concurrent consumers.</param> /// <param name="configurer">The configurer.</param> private void DoTest(int concurrentConsumers, IContainerConfigurer configurer) { var messageCount = 10; var template = new RabbitTemplate(); var connectionFactory = new CachingConnectionFactory(); connectionFactory.ChannelCacheSize = concurrentConsumers; connectionFactory.Port = BrokerTestUtils.GetPort(); template.ConnectionFactory = connectionFactory; var messageConverter = new SimpleMessageConverter(); messageConverter.CreateMessageIds = true; template.MessageConverter = messageConverter; for (var i = 0; i < messageCount; i++) { template.ConvertAndSend(queue1.Name, i); template.ConvertAndSend(queue2.Name, i); } var container = new SimpleMessageListenerContainer(connectionFactory); var latch = new CountdownEvent(messageCount * 2); var listener = new MultiplePocoListener(latch); container.MessageListener = new MessageListenerAdapter(listener); container.AcknowledgeMode = AcknowledgeModeUtils.AcknowledgeMode.Auto; container.ChannelTransacted = true; container.ConcurrentConsumers = concurrentConsumers; configurer.Configure(container); container.AfterPropertiesSet(); container.Start(); try { var timeout = Math.Min((1 + messageCount) / concurrentConsumers, 50); Logger.Info("Timeout: " + timeout); var waited = latch.Wait(timeout * 1000); Logger.Info("All messages recovered: " + waited); Assert.AreEqual(concurrentConsumers, container.ActiveConsumerCount); Assert.True(waited, "Timed out waiting for messages"); } catch (ThreadInterruptedException e) { Thread.CurrentThread.Interrupt(); throw new ThreadStateException("unexpected interruption"); } finally { container.Shutdown(); Assert.AreEqual(0, container.ActiveConsumerCount); } Assert.Null(template.ReceiveAndConvert(queue1.Name)); Assert.Null(template.ReceiveAndConvert(queue2.Name)); }
private bool IsActiveModule(IContainerConfigurer configurer) { return(_engine.Application.ModuleCatalog.IsActiveModuleAssembly(configurer.GetType().Assembly)); }
/// <summary> /// Does the test. /// </summary> /// <param name="concurrentConsumers">The concurrent consumers.</param> /// <param name="configurer">The configurer.</param> /// <remarks></remarks> private void DoTest(int concurrentConsumers, IContainerConfigurer configurer) { var messageCount = 10; var template = new RabbitTemplate(); var connectionFactory = new CachingConnectionFactory(); connectionFactory.ChannelCacheSize = concurrentConsumers; connectionFactory.Port = BrokerTestUtils.GetPort(); template.ConnectionFactory = connectionFactory; var messageConverter = new SimpleMessageConverter(); messageConverter.CreateMessageIds = true; template.MessageConverter = messageConverter; for (var i = 0; i < messageCount; i++) { template.ConvertAndSend(queue1.Name, i.ToString()); template.ConvertAndSend(queue2.Name, i.ToString()); } var container = new SimpleMessageListenerContainer(connectionFactory); var latch = new CountdownEvent(messageCount * 2); var listener = new MultiplePocoListener(latch); container.MessageListener = new MessageListenerAdapter(listener); container.AcknowledgeMode = AcknowledgeModeUtils.AcknowledgeMode.AUTO; container.IsChannelTransacted = true; container.ConcurrentConsumers = concurrentConsumers; configurer.Configure(container); container.AfterPropertiesSet(); container.Start(); try { var timeout = Math.Min((1 + messageCount) / concurrentConsumers, 30); var waited = latch.Wait(timeout * 1000); logger.Info("All messages recovered: " + waited); Assert.AreEqual(concurrentConsumers, container.ActiveConsumerCount); Assert.True(waited, "Timed out waiting for messages"); } catch (ThreadInterruptedException e) { Thread.CurrentThread.Interrupt(); throw new ThreadStateException("unexpected interruption"); } finally { container.Shutdown(); Assert.AreEqual(0, container.ActiveConsumerCount); } Assert.Null(template.ReceiveAndConvert(queue1.Name)); Assert.Null(template.ReceiveAndConvert(queue2.Name)); }
public ContainerConfigurer Add(IContainerConfigurer configurer) { _configurers.Add(configurer); return(this); }