コード例 #1
0
        private void RegisterHandlers(HandlerConfig config)
        {
            // Register events deriving from GenericTask that optonally confirm to our generic usage
            // hoisting custom version for derived types where found.
            RegisterGenericHandlersFor <GenericTask>(config);

            _container.Register(typeof(LoggingContextHandler <>)).AsMultiInstance();
        }
コード例 #2
0
        private void RegisterHandlers(HandlerConfig config)
        {
            // Register traditional Brighter event type with appropriate handler and mapper.
            config.Register <TaskReminderSentEvent, TaskReminderSentEventHandler, TaskReminderSentEventMapper>();

            // Register events deriving from GenericTask that optonally confirm to our generic usage
            // hoisting custom version for derived types where found.
            RegisterGenericHandlersFor <GenericTask>(config);

            _container.Register(typeof(LoggingContextHandler <>)).AsMultiInstance();
        }
コード例 #3
0
        Dispatcher BuildDispatcher(HandlerConfig handlers)
        {
            var policy = BuildPolicy();
            var logger = LogProvider.GetLogger("Brighter");

            return(DispatchBuilder.With()
                   .CommandProcessor(CommandProcessorBuilder.With()
                                     .Handlers(handlers.Handlers)
                                     .Policies(policy)
                                     .NoTaskQueues()
                                     .RequestContextFactory(new InMemoryRequestContextFactory())
                                     .Build())
                   .MessageMappers(handlers.Mappers)
                   .ChannelFactory(new InputChannelFactory(new RmqMessageConsumerFactory(logger), new RmqMessageProducerFactory(logger)))
                   .ConnectionsFromConfiguration()
                   .Build());
        }
コード例 #4
0
        public bool Start(HostControl hostControl)
        {
            log4net.Config.XmlConfigurator.Configure();

            var handlers = new HandlerFactory(_container);
            var mappers  = new MessageMapperFactory(_container);
            var config   = new HandlerConfig(mappers, handlers);

            RegisterHandlers(config);

            _dispatcher = BuildDispatcher(config);

            _container.Register <IAmACommandProcessor>(_dispatcher.CommandProcessor);

            _dispatcher.Receive();

            return(true);
        }
コード例 #5
0
        Dispatcher BuildDispatcher(HandlerConfig handlers)
        {
            var policy = BuildPolicy();

            //create the gateway
            var rmqConnnection = new RmqMessagingGatewayConnection
            {
                AmpqUri  = new AmqpUriSpecification(new Uri("amqp://*****:*****@localhost:5672/%2f")),
                Exchange = new Exchange("paramore.brighter.exchange"),
            };

            //<!-- Events with mapper and handler overrides -->
            //<add connectionName="Task.ReminderSent" channelName="Task.ReminderSent" routingKey="Task.ReminderSent" dataType="Tasks.Ports.Events.TaskReminderSentEvent" noOfPerformers="1" timeOutInMilliseconds="200" />

            //<!-- Generic Events -->
            //<add connectionName="Task.Added" channelName="Task.Added" routingKey="Task.Added" dataType="GenericListener.Ports.Events.GenericTaskAddedEvent" noOfPerformers="1" timeOutInMilliseconds="200" />
            //<add connectionName="Task.Edited" channelName="Task.Edited" routingKey="Task.Edited" dataType="GenericListener.Ports.Events.GenericTaskEditedEvent" noOfPerformers="1" timeOutInMilliseconds="200" />
            //<add connectionName="Task.Completed" channelName="Task.Completed" routingKey="Task.Completed" dataType="GenericListener.Ports.Events.GenericTaskCompletedEvent" noOfPerformers="1" timeOutInMilliseconds="200" />

            var inputChannelFactory = new InputChannelFactory(new RmqMessageConsumerFactory(rmqConnnection), new RmqMessageProducerFactory(rmqConnnection));

            var connections = new List <Connection>
            {
                // Events with mapper and handler overrides
                new Connection(new ConnectionName("Task.ReminderSent"), inputChannelFactory, typeof(Tasks.Ports.Events.TaskReminderSentEvent), new ChannelName("Task.ReminderSent"), "Task.ReminderSent", noOfPerformers: 1, timeoutInMilliseconds: 200),
                // Generic Events
                new Connection(new ConnectionName("Task.Added"), inputChannelFactory, typeof(GenericTaskAddedEvent), new ChannelName("Task.Added"), "Task.Added", noOfPerformers: 1, timeoutInMilliseconds: 200),
                new Connection(new ConnectionName("Task.Edited"), inputChannelFactory, typeof(GenericTaskEditedEvent), new ChannelName("Task.Edited"), "Task.Edited", noOfPerformers: 1, timeoutInMilliseconds: 200),
                new Connection(new ConnectionName("Task.Completed"), inputChannelFactory, typeof(GenericTaskCompletedEvent), new ChannelName("Task.Completed"), "Task.Completed", noOfPerformers: 1, timeoutInMilliseconds: 200),
            };

            return(DispatchBuilder.With()
                   .CommandProcessor(CommandProcessorBuilder.With()
                                     .Handlers(handlers.Handlers)
                                     .Policies(policy)
                                     .NoTaskQueues()
                                     .RequestContextFactory(new InMemoryRequestContextFactory())
                                     .Build())
                   .MessageMappers(handlers.Mappers)
                   .ChannelFactory(inputChannelFactory)
                   //.ConnectionsFromConfiguration()
                   .Connections(connections)
                   .Build());
        }
コード例 #6
0
        private void RegisterGenericHandlersFor <TRequestBase>(HandlerConfig config)
        {
            var baseType = typeof(TRequestBase);

            foreach (var derivedType in EventTypes.Where(t => t.FullName != baseType.FullName && baseType.IsAssignableFrom(t)))
            {
                var handlerImplType = HandlerTypes.FirstOrDefault(t => typeof(IHandleRequests <>).MakeGenericType(derivedType).IsAssignableFrom(t));

                if (handlerImplType == null)
                {
                    var handlerBaseImplType = HandlerTypes.FirstOrDefault(t => t.Name.Equals(baseType.Name + "GenericHandler`1"));

                    if (handlerBaseImplType != null)
                    {
                        handlerImplType = handlerBaseImplType.MakeGenericType(derivedType);
                    }
                }

                var mapperImplType = MapperTypes.FirstOrDefault(t => typeof(IAmAMessageMapper <>).MakeGenericType(derivedType).IsAssignableFrom(t));

                if (mapperImplType == null)
                {
                    var mapperBaseImplType = MapperTypes.FirstOrDefault(t => t.Name.Equals(baseType.Name + "GenericMapper`1"));

                    if (mapperBaseImplType != null)
                    {
                        mapperImplType = mapperBaseImplType.MakeGenericType(derivedType);
                    }
                }

                config.Register(
                    type: derivedType,
                    handler: handlerImplType ?? typeof(GenericHandler <>).MakeGenericType(derivedType),
                    mapper: mapperImplType ?? typeof(GenericMapper <>).MakeGenericType(derivedType));
            }
        }