public virtual void Configure(IMessageDispatcherSettings settings) { if (settings.InputChannel.Value == null) { throw new NoInputChannelConfiguredException("You must specify an input channel for a message dispatcher"); } if (settings.InvalidChannel.Value == null) { throw new NoInputChannelConfiguredException("You must specify an invalid message channel for a message dispatcher"); } if (settings.MessageProcessorTypes.Value == null || settings.MessageProcessorTypes.Value.Count == 0) { throw new NoMessageProcessorsConfiguredException( "You must specify one or more message processors for a message dispatcher"); } if (settings.DurationOfDispatchingSlice.Value.TotalMilliseconds == 0) { throw new NoDispatchingSliceDurationConfiguredException( "You must specify a duration for the dispatcher to dispatch messages during."); } if (settings.NumberOfMessagesToDispatchPerSlice.Value == 0) { throw new NoNumberOfMessagesPerSliceConfiguredException( "You must specify the maximum number of messages to be dispatched during a slice of time."); } CurrentSettings = settings; InputChannel = settings.InputChannel.Value; InvalidChannel = settings.InvalidChannel.Value; MessageProcessors = new List<IMessageProcessor>(); foreach (var type in CurrentSettings.MessageProcessorTypes.Value) { var processor = Container.GetInstance(type) as IMessageProcessor; if (processor == null) { continue; } this.WriteInfoMessage(string.Format("Adding processor {0} to dispatcher.", processor.GetType().Name)); MessageProcessors.Add(processor); } this.WriteInfoMessage( string.Format( "Dispatcher configured with input channel {0}({1}) and {2} message processors.", InputChannel.GetType().Name, InputChannel.ChannelName, MessageProcessors.Count())); Configured = true; }
public void Setup() { BasicConfigurator.Configure(); ConfigureContainer(); _dispatcherSettings = new MessageDispatcherSettings(); _dispatcherSettings.InvalidChannel.WithDefault(_container.Resolve<IMessageChannel>("invalid")); _dispatcherSettings.InputChannel.WithDefault(_container.Resolve<IMessageChannel>("input")); _dispatcherSettings.NumberOfMessagesToDispatchPerSlice.WithDefault(20); _dispatcherSettings.DurationOfDispatchingSlice.WithDefault(new TimeSpan(0, 0, 0, 0, 500)); _dispatcherSettings.MessageProcessorTypes.WithDefault(new List<Type> { typeof(FakeCommandProcessor) }); _locator = new WindsorServiceLocator(_container); }