Ejemplo n.º 1
0
        public static ENodeConfiguration StartKafka(this ENodeConfiguration enodeConfiguration)
        {
            var kafkaConfig = ObjectContainer.Resolve <Jane.ENode.IKafkaConfiguration>();

            var producerSetting = new ProducerSetting
            {
                BrokerEndPoints = kafkaConfig.BrokerEndPoints
            };
            var commandConsumerSetting = new ConsumerSetting
            {
                BrokerEndPoints = kafkaConfig.BrokerEndPoints,
                GroupName       = "BoundedContextCommandConsumerGroup"
            };
            var eventConsumerSetting = new ConsumerSetting
            {
                BrokerEndPoints = kafkaConfig.BrokerEndPoints,
                GroupName       = "BoundedContextDomainEventConsumerGroup"
            };
            var applicationMessageConsumerSetting = new ConsumerSetting
            {
                BrokerEndPoints = kafkaConfig.BrokerEndPoints,
                GroupName       = "BoundedContextApplicationMessageConsumerGroup"
            };
            var domainExceptionConsumerSetting = new ConsumerSetting
            {
                BrokerEndPoints = kafkaConfig.BrokerEndPoints,
                GroupName       = "BoundedContextDomainExceptionConsumerGroup"
            };

            _commandConsumer = new CommandConsumer()
                               .InitializeKafka(commandConsumerSetting)
                               .Subscribe(new List <string>()
            {
                BoundedContextTopics.BoundedContextDomainCommandTopic
            });
            _eventConsumer = new DomainEventConsumer()
                             .InitializeKafka(eventConsumerSetting)
                             .Subscribe(new List <string>()
            {
                BoundedContextTopics.BoundedContextDomainDomainEventTopic
            });
            _applicationMessageConsumer = new ApplicationMessageConsumer()
                                          .InitializeKafka(applicationMessageConsumerSetting)
                                          .Subscribe(new List <string>()
            {
                BoundedContextTopics.BoundedContextDomainApplicationMessageTopic
            });
            _domainExceptionConsumer = new DomainExceptionConsumer()
                                       .InitializeKafka(domainExceptionConsumerSetting)
                                       .Subscribe(new List <string>()
            {
                BoundedContextTopics.BoundedContextDomainExceptionTopic
            });

            _commandResultProcessor = new CommandResultProcessor()
                                      .Initialize(new IPEndPoint(SocketUtils.GetLocalIPV4(), 9003));
            _commandService.InitializeKafka(producerSetting, _commandResultProcessor);
            _eventPublisher.InitializeKafka(producerSetting);
            _applicationMessagePublisher.InitializeKafka(producerSetting);
            _domainExceptionPublisher.InitializeKafka(producerSetting);

            _commandConsumer.Start();
            _eventConsumer.Start();
            _applicationMessageConsumer.Start();
            _domainExceptionConsumer.Start();

            _commandResultProcessor.Start();
            _commandService.Start();
            _eventPublisher.Start();
            _applicationMessagePublisher.Start();
            _domainExceptionPublisher.Start();

            return(enodeConfiguration);
        }
        public static ENodeConfiguration StartKafka(this ENodeConfiguration enodeConfiguration)
        {
            var produceSetting = new ProducerSetting()
            {
                BrokerEndPoints = _brokerEndPoints
            };
            var commandConsumerSetting = new ConsumerSetting
            {
                BrokerEndPoints = _brokerEndPoints,
                CommitConsumerOffsetInterval = 100,
                GroupName = "CommandConsumerGroup"
            };
            var eventConsumerSetting = new ConsumerSetting
            {
                BrokerEndPoints = _brokerEndPoints,
                CommitConsumerOffsetInterval = 100,
                GroupName = "DomainEventConsumerGroup"
            };
            var applicationMessageConsumerSetting = new ConsumerSetting
            {
                BrokerEndPoints = _brokerEndPoints,
                CommitConsumerOffsetInterval = 100,
                GroupName = "ApplicationMessageConsumerGroup"
            };
            var domainExceptionConsumerSetting = new ConsumerSetting
            {
                BrokerEndPoints = _brokerEndPoints,
                CommitConsumerOffsetInterval = 100,
                GroupName = "DomainExceptionConsumerGroup"
            };

            _commandConsumer = new CommandConsumer()
                               .InitializeKafka(commandConsumerSetting)
                               .Subscribe("CommandTopic");
            _eventConsumer = new DomainEventConsumer()
                             .InitializeKafka(eventConsumerSetting)
                             .Subscribe("EventTopic");
            _applicationMessageConsumer = new ApplicationMessageConsumer()
                                          .InitializeKafka(applicationMessageConsumerSetting)
                                          .Subscribe("ApplicationMessageTopic");
            _domainExceptionConsumer = new DomainExceptionConsumer()
                                       .InitializeKafka(domainExceptionConsumerSetting)
                                       .Subscribe("DomainExceptionTopic");

            _commandResultProcessor = new CommandResultProcessor()
                                      .Initialize(new IPEndPoint(SocketUtils.GetLocalIPV4(), 9003));
            _commandService.InitializeKafka(produceSetting, _commandResultProcessor);
            _eventPublisher.InitializeKafka(produceSetting);
            _applicationMessagePublisher.InitializeKafka(produceSetting);
            _domainExceptionPublisher.InitializeKafka(produceSetting);

            _commandConsumer.Start();
            _eventConsumer.Start();
            _applicationMessageConsumer.Start();
            _domainExceptionConsumer.Start();

            _commandService.Start();
            _eventPublisher.Start();
            _applicationMessagePublisher.Start();
            _domainExceptionPublisher.Start();

            return(enodeConfiguration);
        }