Beispiel #1
0
        public static ENodeConfiguration UseEQueue(this ENodeConfiguration enodeConfiguration)
        {
            var configuration   = enodeConfiguration.GetCommonConfiguration();
            var brokerStorePath = @"d:\equeue-store";

            if (Directory.Exists(brokerStorePath))
            {
                Directory.Delete(brokerStorePath, true);
            }

            configuration.RegisterEQueueComponents();

            _broker = BrokerController.Create();

            _commandResultProcessor      = new CommandResultProcessor(new IPEndPoint(SocketUtils.GetLocalIPV4(), 9000));
            _commandService              = new CommandService(_commandResultProcessor);
            _applicationMessagePublisher = new ApplicationMessagePublisher();
            _domainEventPublisher        = new DomainEventPublisher();
            _exceptionPublisher          = new PublishableExceptionPublisher();

            configuration.SetDefault <ICommandService, CommandService>(_commandService);
            configuration.SetDefault <IMessagePublisher <IApplicationMessage>, ApplicationMessagePublisher>(_applicationMessagePublisher);
            configuration.SetDefault <IMessagePublisher <DomainEventStreamMessage>, DomainEventPublisher>(_domainEventPublisher);
            configuration.SetDefault <IMessagePublisher <IPublishableException>, PublishableExceptionPublisher>(_exceptionPublisher);

            _commandConsumer            = new CommandConsumer().Subscribe("BankTransferCommandTopic");
            _applicationMessageConsumer = new ApplicationMessageConsumer().Subscribe("BankTransferApplicationMessageTopic");
            _eventConsumer     = new DomainEventConsumer().Subscribe("BankTransferEventTopic");
            _exceptionConsumer = new PublishableExceptionConsumer().Subscribe("BankTransferExceptionTopic");

            return(enodeConfiguration);
        }
Beispiel #2
0
        public static ENodeConfiguration UseEQueue(this ENodeConfiguration enodeConfiguration)
        {
            var configuration = enodeConfiguration.GetCommonConfiguration();

            configuration.RegisterEQueueComponents();

            _broker = new BrokerController();

            _commandResultProcessor      = new CommandResultProcessor();
            _commandService              = new CommandService(_commandResultProcessor);
            _applicationMessagePublisher = new ApplicationMessagePublisher();
            _domainEventPublisher        = new DomainEventPublisher();
            _exceptionPublisher          = new PublishableExceptionPublisher();

            configuration.SetDefault <ICommandService, CommandService>(_commandService);
            configuration.SetDefault <IMessagePublisher <IApplicationMessage>, ApplicationMessagePublisher>(_applicationMessagePublisher);
            configuration.SetDefault <IMessagePublisher <DomainEventStreamMessage>, DomainEventPublisher>(_domainEventPublisher);
            configuration.SetDefault <IMessagePublisher <IPublishableException>, PublishableExceptionPublisher>(_exceptionPublisher);

            _commandConsumer            = new CommandConsumer().Subscribe("BankTransferCommandTopic");
            _applicationMessageConsumer = new ApplicationMessageConsumer().Subscribe("BankTransferApplicationMessageTopic");
            _eventConsumer     = new DomainEventConsumer().Subscribe("BankTransferEventTopic");
            _exceptionConsumer = new PublishableExceptionConsumer().Subscribe("BankTransferExceptionTopic");

            return(enodeConfiguration);
        }
Beispiel #3
0
        public static ENodeConfiguration StartEQueue(this ENodeConfiguration enodeConfiguration)
        {
            var producerSetting = new ProducerSetting
            {
                NameServerList = new List <IPEndPoint> {
                    new IPEndPoint(SocketUtils.GetLocalIPV4(), ConfigSettings.NameServerPort)
                }
            };
            var consumerSetting = new ConsumerSetting
            {
                NameServerList = new List <IPEndPoint> {
                    new IPEndPoint(SocketUtils.GetLocalIPV4(), ConfigSettings.NameServerPort)
                }
            };

            _domainEventPublisher.InitializeEQueue(producerSetting);
            _commandService.InitializeEQueue(null, producerSetting);

            _commandConsumer            = new CommandConsumer().InitializeEQueue("RegistrationCommandConsumerGroup", consumerSetting).Subscribe(Topics.RegistrationCommandTopic);
            _eventConsumer              = new DomainEventConsumer().InitializeEQueue("RegistrationEventConsumerGroup", consumerSetting).Subscribe(Topics.RegistrationDomainEventTopic);
            _applicationMessageConsumer = new ApplicationMessageConsumer().InitializeEQueue("RegistrationMessageConsumerGroup", consumerSetting)
                                          .Subscribe(Topics.ConferenceApplicationMessageTopic)
                                          .Subscribe(Topics.PaymentApplicationMessageTopic);

            _applicationMessageConsumer.Start();
            _eventConsumer.Start();
            _commandConsumer.Start();
            _domainEventPublisher.Start();
            _commandService.Start();

            return(enodeConfiguration);
        }
Beispiel #4
0
        public static ENodeConfiguration UseEQueue(this ENodeConfiguration enodeConfiguration)
        {
            var configuration = enodeConfiguration.GetCommonConfiguration();

            configuration.RegisterEQueueComponents();

            var producerSetting = new ProducerSetting
            {
                BrokerAddress      = new IPEndPoint(SocketUtils.GetLocalIPV4(), ConfigSettings.BrokerProducerPort),
                BrokerAdminAddress = new IPEndPoint(SocketUtils.GetLocalIPV4(), ConfigSettings.BrokerAdminPort)
            };
            var consumerSetting = new ConsumerSetting
            {
                BrokerAddress      = new IPEndPoint(SocketUtils.GetLocalIPV4(), ConfigSettings.BrokerConsumerPort),
                BrokerAdminAddress = new IPEndPoint(SocketUtils.GetLocalIPV4(), ConfigSettings.BrokerAdminPort)
            };

            _domainEventPublisher = new DomainEventPublisher(producerSetting);

            configuration.SetDefault <IMessagePublisher <DomainEventStreamMessage>, DomainEventPublisher>(_domainEventPublisher);

            _commandService = new CommandService(null, producerSetting);

            configuration.SetDefault <ICommandService, CommandService>(_commandService);

            _commandConsumer            = new CommandConsumer("RegistrationCommandConsumerGroup", consumerSetting).Subscribe(Topics.RegistrationCommandTopic);
            _eventConsumer              = new DomainEventConsumer("RegistrationEventConsumerGroup", consumerSetting).Subscribe(Topics.RegistrationDomainEventTopic);
            _applicationMessageConsumer = new ApplicationMessageConsumer("RegistrationMessageConsumerGroup", consumerSetting)
                                          .Subscribe(Topics.ConferenceApplicationMessageTopic)
                                          .Subscribe(Topics.PaymentApplicationMessageTopic);

            return(enodeConfiguration);
        }
Beispiel #5
0
        public static ENodeConfiguration UseEQueue(this ENodeConfiguration enodeConfiguration)
        {
            var configuration = enodeConfiguration.GetCommonConfiguration();

            configuration.RegisterEQueueComponents();
            var producerSetting = new ProducerSetting
            {
                BrokerAddress      = new IPEndPoint(ConfigSettings.BrokerAddress, ConfigSettings.BrokerProducerPort),
                BrokerAdminAddress = new IPEndPoint(ConfigSettings.BrokerAddress, ConfigSettings.BrokerAdminPort)
            };
            var consumerSetting = new ConsumerSetting
            {
                BrokerAddress      = new IPEndPoint(ConfigSettings.BrokerAddress, ConfigSettings.BrokerConsumerPort),
                BrokerAdminAddress = new IPEndPoint(ConfigSettings.BrokerAddress, ConfigSettings.BrokerAdminPort)
            };

            _applicationMessagePublisher = new ApplicationMessagePublisher(producerSetting);
            _domainEventPublisher        = new DomainEventPublisher(producerSetting);
            _exceptionPublisher          = new PublishableExceptionPublisher(producerSetting);

            configuration.SetDefault <IMessagePublisher <IApplicationMessage>, ApplicationMessagePublisher>(_applicationMessagePublisher);
            configuration.SetDefault <IMessagePublisher <DomainEventStreamMessage>, DomainEventPublisher>(_domainEventPublisher);
            configuration.SetDefault <IMessagePublisher <IPublishableException>, PublishableExceptionPublisher>(_exceptionPublisher);

            _commandConsumer            = new CommandConsumer("NCasCommandConsumerGroup", consumerSetting).Subscribe(Topics.NCasCommandTopic);
            _applicationMessageConsumer = new ApplicationMessageConsumer("NCasApplicationMessageConsumerGroup", consumerSetting).Subscribe(Topics.NCasApplicationMessageTopic);
            _eventConsumer     = new DomainEventConsumer("NCasEventConsumerGroup", consumerSetting).Subscribe(Topics.NCasDomainEventTopic);
            _exceptionConsumer = new PublishableExceptionConsumer("NCasExceptionConsumerGroup", consumerSetting).Subscribe(Topics.NCasExceptionTopic);

            return(enodeConfiguration);
        }
Beispiel #6
0
        public static ENodeConfiguration UseEQueue(this ENodeConfiguration enodeConfiguration)
        {
            var configuration = enodeConfiguration.GetCommonConfiguration();

            configuration.RegisterEQueueComponents();

            //生产者设置
            var producerSetting = new ProducerSetting
            {
                NameServerList = new List <IPEndPoint> {
                    new IPEndPoint(SocketUtils.GetLocalIPV4(), ConfigSettings.NameServerPort)
                }
            };
            //消费者设置
            var consumerSetting = new ConsumerSetting
            {
                NameServerList = new List <IPEndPoint> {
                    new IPEndPoint(SocketUtils.GetLocalIPV4(), ConfigSettings.NameServerPort)
                }
            };

            //命令生成者
            _commandService = new CommandService();
            _commandService.Initialize(setting: producerSetting);
            //事件生产者
            _domainEventPublisher = new DomainEventPublisher().Initialize(setting: producerSetting);
            //消息生产者
            _applicationMessagePublisher = new ApplicationMessagePublisher().Initialize(setting: producerSetting);
            //异常生产者
            _exceptionPublisher = new PublishableExceptionPublisher().Initialize(setting: producerSetting);

            configuration.SetDefault <ICommandService, CommandService>(_commandService);
            configuration.SetDefault <IMessagePublisher <DomainEventStreamMessage>, DomainEventPublisher>(_domainEventPublisher);
            configuration.SetDefault <IMessagePublisher <IApplicationMessage>, ApplicationMessagePublisher>(_applicationMessagePublisher);
            configuration.SetDefault <IMessagePublisher <IPublishableException>, PublishableExceptionPublisher>(_exceptionPublisher);

            //命令消费者
            _commandConsumer = new CommandConsumer().Initialize(setting: consumerSetting)
                               .Subscribe(Topics.ShopCommandTopic);
            //事件消费者
            _eventConsumer = new DomainEventConsumer().Initialize(setting: consumerSetting)
                             .Subscribe(Topics.ShopDomainEventTopic);

            //消息消费者
            _applicationMessageConsumer = new ApplicationMessageConsumer().Initialize(setting: consumerSetting)
                                          .Subscribe(Topics.ShopApplicationMessageTopic);
            //异常消费者
            _exceptionConsumer = new PublishableExceptionConsumer().Initialize(setting: consumerSetting)
                                 .Subscribe(Topics.ShopExceptionTopic);

            return(enodeConfiguration);
        }
Beispiel #7
0
        public static ENodeConfiguration StartKafka(this ENodeConfiguration enodeConfiguration)
        {
            if (_isKafkaStarted)
            {
                _commandService.InitializeENode();
                _eventPublisher.InitializeENode();
                _applicationMessagePublisher.InitializeENode();
                _publishableExceptionPublisher.InitializeENode();

                _commandConsumer.InitializeENode();
                _eventConsumer.InitializeENode();
                _applicationMessageConsumer.InitializeENode();
                _publishableExceptionConsumer.InitializeENode();

                return(enodeConfiguration);
            }

            var produceSetting = new ProducerSetting()
            {
                BrokerEndPoints = _brokerEndPoints
            };

            _commandService.InitializeKafka(produceSetting, new CommandResultProcessor().Initialize(SocketUtils.GetLocalIPV4().ToString(), 9001));//Dns.GetHostName()
            _eventPublisher.InitializeKafka(produceSetting);
            _applicationMessagePublisher.InitializeKafka(produceSetting);
            _publishableExceptionPublisher.InitializeKafka(produceSetting);

            var consumerSetting = new ConsumerSetting()
            {
                BrokerEndPoints = _brokerEndPoints,
                CommitConsumerOffsetInterval = 100
            };

            _commandConsumer              = new CommandConsumer().InitializeKafka(consumerSetting).Subscribe("CommandTopic");
            _eventConsumer                = new DomainEventConsumer().InitializeKafka(consumerSetting).Subscribe("EventTopic");
            _applicationMessageConsumer   = new ApplicationMessageConsumer().InitializeKafka(consumerSetting).Subscribe("ApplicationMessageTopic");
            _publishableExceptionConsumer = new PublishableExceptionConsumer().InitializeKafka(consumerSetting).Subscribe("PublishableExceptionTopic");

            _eventConsumer.Start();
            _commandConsumer.Start();
            _applicationMessageConsumer.Start();
            _publishableExceptionConsumer.Start();
            _applicationMessagePublisher.Start();
            _publishableExceptionPublisher.Start();
            _eventPublisher.Start();
            _commandService.Start();

            _isKafkaStarted = true;

            return(enodeConfiguration);
        }
        public static ENodeConfiguration StartEQueue(this ENodeConfiguration enodeConfiguration)
        {
            var brokerStorePath = ConfigurationManager.AppSettings["equeue-store-path"];

            if (Directory.Exists(brokerStorePath))
            {
                Directory.Delete(brokerStorePath, true);
            }

            _commandService.InitializeEQueue(new CommandResultProcessor().Initialize(new IPEndPoint(SocketUtils.GetLocalIPV4(), 9001)));
            _applicationMessagePublisher.InitializeEQueue();
            _domainEventPublisher.InitializeEQueue();
            _exceptionPublisher.InitializeEQueue();

            _nameServerController = new NameServerController();
            _broker = BrokerController.Create(new BrokerSetting(chunkFileStoreRootPath: brokerStorePath));

            _commandConsumer            = new CommandConsumer().InitializeEQueue().Subscribe(Constants.CommandTopic);
            _applicationMessageConsumer = new ApplicationMessageConsumer().InitializeEQueue().Subscribe(Constants.ApplicationMessageTopic);
            _eventConsumer     = new DomainEventConsumer().InitializeEQueue().Subscribe(Constants.EventTopic);
            _exceptionConsumer = new DomainExceptionConsumer().InitializeEQueue().Subscribe(Constants.ExceptionTopic);
            _nameServerSocketRemotingClient = new SocketRemotingClient("NameServerRemotingClient", new IPEndPoint(SocketUtils.GetLocalIPV4(), 9493));

            _nameServerController.Start();
            _broker.Start();
            _exceptionConsumer.Start();
            _eventConsumer.Start();
            _applicationMessageConsumer.Start();
            _commandConsumer.Start();
            _applicationMessagePublisher.Start();
            _domainEventPublisher.Start();
            _exceptionPublisher.Start();
            _commandService.Start();
            _nameServerSocketRemotingClient.Start();

            //生产环境不需要以下这段代码
            CreateTopic(Constants.CommandTopic);
            CreateTopic(Constants.EventTopic);
            CreateTopic(Constants.ApplicationMessageTopic);
            CreateTopic(Constants.ExceptionTopic);
            WaitAllProducerTopicQueuesAvailable();
            WaitAllConsumerLoadBalanceComplete();

            return(enodeConfiguration);
        }
Beispiel #9
0
        public static ENodeConfiguration StartEQueue(this ENodeConfiguration enodeConfiguration)
        {
            var brokerStorePath = @"c:\equeue-store-ut";
            var brokerSetting   = new BrokerSetting(chunkFileStoreRootPath: brokerStorePath);

            if (Directory.Exists(brokerStorePath))
            {
                Directory.Delete(brokerStorePath, true);
            }

            _nameServerController = new NameServerController();
            _broker = BrokerController.Create(brokerSetting);

            _commandService.Initialize(new CommandResultProcessor().Initialize(new IPEndPoint(SocketUtils.GetLocalIPV4(), 9001)));
            _eventPublisher.Initialize();
            _applicationMessagePublisher.Initialize();
            _publishableExceptionPublisher.Initialize();

            _commandConsumer = new CommandConsumer().Initialize(setting: new ConsumerSetting {
                ConsumeFromWhere = ConsumeFromWhere.FirstOffset
            }).Subscribe("CommandTopic");
            _eventConsumer = new DomainEventConsumer().Initialize(setting: new ConsumerSetting {
                ConsumeFromWhere = ConsumeFromWhere.FirstOffset
            }).Subscribe("EventTopic");
            _applicationMessageConsumer = new ApplicationMessageConsumer().Initialize(setting: new ConsumerSetting {
                ConsumeFromWhere = ConsumeFromWhere.FirstOffset
            }).Subscribe("ApplicationMessageTopic");
            _publishableExceptionConsumer = new PublishableExceptionConsumer().Initialize(setting: new ConsumerSetting {
                ConsumeFromWhere = ConsumeFromWhere.FirstOffset
            }).Subscribe("PublishableExceptionTopic");

            _nameServerController.Start();
            _broker.Start();
            _eventConsumer.Start();
            _commandConsumer.Start();
            _applicationMessageConsumer.Start();
            _publishableExceptionConsumer.Start();
            _applicationMessagePublisher.Start();
            _publishableExceptionPublisher.Start();
            _eventPublisher.Start();
            _commandService.Start();
            WaitAllConsumerLoadBalanceComplete();
            return(enodeConfiguration);
        }
Beispiel #10
0
        public static ENodeConfiguration StartEQueue(this ENodeConfiguration enodeConfiguration)
        {
            _commandService.Initialize(new CommandResultProcessor().Initialize(new IPEndPoint(SocketUtils.GetLocalIPV4(), 9000)));
            _applicationMessagePublisher.Initialize();
            _domainEventPublisher.Initialize();
            _exceptionPublisher.Initialize();

            _nameServerController = new NameServerController();
            _broker = BrokerController.Create();

            _commandConsumer            = new CommandConsumer().Initialize().Subscribe("BankTransferCommandTopic");
            _applicationMessageConsumer = new ApplicationMessageConsumer().Initialize().Subscribe("BankTransferApplicationMessageTopic");
            _eventConsumer     = new DomainEventConsumer().Initialize().Subscribe("BankTransferEventTopic");
            _exceptionConsumer = new PublishableExceptionConsumer().Initialize().Subscribe("BankTransferExceptionTopic");

            var brokerStorePath = @"c:\equeue-store";

            if (Directory.Exists(brokerStorePath))
            {
                Directory.Delete(brokerStorePath, true);
            }

            _nameServerController.Start();
            _broker.Start();
            _exceptionConsumer.Start();
            _eventConsumer.Start();
            _applicationMessageConsumer.Start();
            _commandConsumer.Start();
            _applicationMessagePublisher.Start();
            _domainEventPublisher.Start();
            _exceptionPublisher.Start();
            _commandService.Start();

            WaitAllConsumerLoadBalanceComplete();

            return(enodeConfiguration);
        }
Beispiel #11
0
        public static ENodeConfiguration StartEQueue(this ENodeConfiguration enodeConfiguration)
        {
            if (_isEQueueStarted)
            {
                _commandService.InitializeENode();
                _eventPublisher.InitializeENode();
                _applicationMessagePublisher.InitializeENode();
                _domainExceptionPublisher.InitializeENode();

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

                return(enodeConfiguration);
            }

            var brokerStorePath = @"d:\equeue-store-enode-ut";
            var brokerSetting   = new BrokerSetting(chunkFileStoreRootPath: brokerStorePath);

            if (Directory.Exists(brokerStorePath))
            {
                Directory.Delete(brokerStorePath, true);
            }

            _nameServerController = new NameServerController();
            _broker = BrokerController.Create(brokerSetting);

            _commandService.InitializeEQueue(new CommandResultProcessor().Initialize(new IPEndPoint(SocketUtils.GetLocalIPV4(), 9001)));
            _eventPublisher.InitializeEQueue();
            _applicationMessagePublisher.InitializeEQueue();
            _domainExceptionPublisher.InitializeEQueue();

            _commandConsumer = new CommandConsumer().InitializeEQueue(setting: new ConsumerSetting {
                ConsumeFromWhere = ConsumeFromWhere.LastOffset
            }).Subscribe("CommandTopic");
            _eventConsumer = new DomainEventConsumer().InitializeEQueue(setting: new ConsumerSetting {
                ConsumeFromWhere = ConsumeFromWhere.LastOffset
            }).Subscribe("EventTopic");
            _applicationMessageConsumer = new ApplicationMessageConsumer().InitializeEQueue(setting: new ConsumerSetting {
                ConsumeFromWhere = ConsumeFromWhere.LastOffset
            }).Subscribe("ApplicationMessageTopic");
            _domainExceptionConsumer = new DomainExceptionConsumer().InitializeEQueue(setting: new ConsumerSetting {
                ConsumeFromWhere = ConsumeFromWhere.LastOffset
            }).Subscribe("DomainExceptionTopic");
            _nameServerSocketRemotingClient = new SocketRemotingClient("NameServerRemotingClient", new IPEndPoint(SocketUtils.GetLocalIPV4(), 9493));

            _nameServerController.Start();
            _broker.Start();
            _eventConsumer.Start();
            _commandConsumer.Start();
            _applicationMessageConsumer.Start();
            _domainExceptionConsumer.Start();
            _applicationMessagePublisher.Start();
            _domainExceptionPublisher.Start();
            _eventPublisher.Start();
            _commandService.Start();
            _nameServerSocketRemotingClient.Start();

            CreateTopic(Constants.CommandTopic);
            CreateTopic(Constants.EventTopic);
            CreateTopic(Constants.ApplicationMessageTopic);
            CreateTopic(Constants.ExceptionTopic);
            WaitAllProducerTopicQueuesAvailable();
            WaitAllConsumerLoadBalanceComplete();

            _isEQueueStarted = true;

            return(enodeConfiguration);
        }
        public static ENodeConfiguration StartRabbitMQ(this ENodeConfiguration enodeConfiguration)
        {
            var amqpUri    = new Uri("amqp://*****:*****@localhost/test");
            var clientName = "BankTransferSample";

            _commandService.InitializeRabbitMQ(new ProducerSettings
            {
                AmqpUri    = amqpUri,
                ClientName = clientName
            },
                                               new string[] { Constants.CommandTopic },
                                               new CommandResultProcessor().Initialize(new IPEndPoint(SocketUtils.GetLocalIPV4(), 9000)));
            _applicationMessagePublisher.InitializeRabbitMQ(new ProducerSettings
            {
                AmqpUri    = amqpUri,
                ClientName = clientName
            },
                                                            new string[] { Constants.ApplicationMessageTopic });
            _domainEventPublisher.InitializeRabbitMQ(new ProducerSettings
            {
                AmqpUri    = amqpUri,
                ClientName = clientName
            },
                                                     new string[] { Constants.EventTopic });
            _exceptionPublisher.InitializeRabbitMQ(new ProducerSettings
            {
                AmqpUri    = amqpUri,
                ClientName = clientName
            },
                                                   new string[] { Constants.ExceptionTopic });

            _commandConsumer = new CommandConsumer().InitializeRabbitMQ(new ConsumerSettings
            {
                AmqpUri       = amqpUri,
                ClientName    = clientName,
                Mode          = ConsumeMode.Pull,
                PrefetchCount = (ushort)ENode.Configurations.ENodeConfiguration.Instance.Setting.EventMailBoxPersistenceMaxBatchSize
            }).Subscribe(Constants.CommandTopic);
            _applicationMessageConsumer = new ApplicationMessageConsumer().InitializeRabbitMQ(new ConsumerSettings
            {
                AmqpUri       = amqpUri,
                ClientName    = clientName,
                Mode          = ConsumeMode.Pull,
                PrefetchCount = (ushort)ENode.Configurations.ENodeConfiguration.Instance.Setting.EventMailBoxPersistenceMaxBatchSize
            }).Subscribe(Constants.ApplicationMessageTopic);
            _eventConsumer = new DomainEventConsumer().InitializeRabbitMQ(new ConsumerSettings
            {
                AmqpUri       = amqpUri,
                ClientName    = clientName,
                Mode          = ConsumeMode.Pull,
                PrefetchCount = (ushort)ENode.Configurations.ENodeConfiguration.Instance.Setting.EventMailBoxPersistenceMaxBatchSize
            }).Subscribe(Constants.EventTopic);
            _exceptionConsumer = new DomainExceptionConsumer().InitializeRabbitMQ(new ConsumerSettings
            {
                AmqpUri       = amqpUri,
                ClientName    = clientName,
                Mode          = ConsumeMode.Pull,
                PrefetchCount = (ushort)ENode.Configurations.ENodeConfiguration.Instance.Setting.EventMailBoxPersistenceMaxBatchSize
            }).Subscribe(Constants.ExceptionTopic);

            _exceptionConsumer.Start();
            _eventConsumer.Start();
            _applicationMessageConsumer.Start();
            _commandConsumer.Start();
            _applicationMessagePublisher.Start();
            _domainEventPublisher.Start();
            _exceptionPublisher.Start();
            _commandService.Start();

            return(enodeConfiguration);
        }
Beispiel #13
0
        public static ENodeConfiguration StartEQueue(this ENodeConfiguration enodeConfiguration)
        {
            if (_isEQueueStarted)
            {
                _commandService.InitializeENode();
                _eventPublisher.InitializeENode();
                _applicationMessagePublisher.InitializeENode();
                _domainExceptionPublisher.InitializeENode();

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

                return(enodeConfiguration);
            }

            var localIp           = SocketUtils.GetLocalIPV4();
            var nameserverPoint   = 9493;
            var nameserverSetting = new NameServerSetting {
                BindingAddress = new IPEndPoint(localIp, nameserverPoint)
            };
            var brokerStorePath = @"d:\equeue-store-enode-ut";
            var brokerSetting   = new BrokerSetting(chunkFileStoreRootPath: brokerStorePath)
            {
                NameServerList = new List <IPEndPoint> {
                    new IPEndPoint(localIp, nameserverPoint)
                }
            };

            brokerSetting.BrokerInfo.ProducerAddress = new IPEndPoint(localIp, 5000).ToAddress();
            brokerSetting.BrokerInfo.ConsumerAddress = new IPEndPoint(localIp, 5001).ToAddress();
            brokerSetting.BrokerInfo.AdminAddress    = new IPEndPoint(localIp, 5002).ToAddress();

            var producerSetting = new ProducerSetting
            {
                NameServerList = new List <IPEndPoint> {
                    new IPEndPoint(localIp, nameserverPoint)
                }
            };
            var consumerSetting = new ConsumerSetting
            {
                NameServerList = new List <IPEndPoint> {
                    new IPEndPoint(localIp, nameserverPoint)
                },
                ConsumeFromWhere = ConsumeFromWhere.LastOffset
            };

            if (Directory.Exists(brokerStorePath))
            {
                Directory.Delete(brokerStorePath, true);
            }

            _nameServerController = new NameServerController(nameserverSetting);
            _broker = BrokerController.Create(brokerSetting);

            var commandResultProcessor = new CommandResultProcessor().Initialize(new IPEndPoint(localIp, 9001));

            _commandService.InitializeEQueue(commandResultProcessor, producerSetting);
            _eventPublisher.InitializeEQueue(producerSetting);
            _applicationMessagePublisher.InitializeEQueue(producerSetting);
            _domainExceptionPublisher.InitializeEQueue(producerSetting);

            _commandConsumer                = new CommandConsumer().InitializeEQueue(setting: consumerSetting).Subscribe("CommandTopic");
            _eventConsumer                  = new DomainEventConsumer().InitializeEQueue(setting: consumerSetting).Subscribe("EventTopic");
            _applicationMessageConsumer     = new ApplicationMessageConsumer().InitializeEQueue(setting: consumerSetting).Subscribe("ApplicationMessageTopic");
            _domainExceptionConsumer        = new DomainExceptionConsumer().InitializeEQueue(setting: consumerSetting).Subscribe("DomainExceptionTopic");
            _nameServerSocketRemotingClient = new SocketRemotingClient("NameServerRemotingClient", new IPEndPoint(localIp, nameserverPoint));

            _nameServerController.Start();
            _broker.Start();
            _eventConsumer.Start();
            _commandConsumer.Start();
            _applicationMessageConsumer.Start();
            _domainExceptionConsumer.Start();
            _applicationMessagePublisher.Start();
            _domainExceptionPublisher.Start();
            _eventPublisher.Start();
            _commandService.Start();
            _nameServerSocketRemotingClient.Start();

            CreateTopic(Constants.CommandTopic);
            CreateTopic(Constants.EventTopic);
            CreateTopic(Constants.ApplicationMessageTopic);
            CreateTopic(Constants.ExceptionTopic);
            WaitAllProducerTopicQueuesAvailable();
            WaitAllConsumerLoadBalanceComplete();

            _isEQueueStarted = true;

            return(enodeConfiguration);
        }
Beispiel #14
0
        public static ENodeConfiguration UseEQueue(this ENodeConfiguration enodeConfiguration,
                                                   bool useMockDomainEventPublisher          = false,
                                                   bool useMockApplicationMessagePublisher   = false,
                                                   bool useMockPublishableExceptionPublisher = false)
        {
            var configuration   = enodeConfiguration.GetCommonConfiguration();
            var brokerStorePath = @"c:\equeue-store";
            var brokerSetting   = new BrokerSetting(brokerStorePath);

            if (Directory.Exists(brokerStorePath))
            {
                Directory.Delete(brokerStorePath, true);
            }

            configuration.RegisterEQueueComponents();
            _broker         = BrokerController.Create(brokerSetting);
            _commandService = new CommandService(new CommandResultProcessor(new IPEndPoint(SocketUtils.GetLocalIPV4(), 9001)));
            _eventPublisher = new DomainEventPublisher();
            _applicationMessagePublisher   = new ApplicationMessagePublisher();
            _publishableExceptionPublisher = new PublishableExceptionPublisher();

            if (useMockDomainEventPublisher)
            {
                configuration.SetDefault <IMessagePublisher <DomainEventStreamMessage>, MockDomainEventPublisher>();
            }
            else
            {
                configuration.SetDefault <IMessagePublisher <DomainEventStreamMessage>, DomainEventPublisher>(_eventPublisher);
            }

            if (useMockApplicationMessagePublisher)
            {
                configuration.SetDefault <IMessagePublisher <IApplicationMessage>, MockApplicationMessagePublisher>();
            }
            else
            {
                configuration.SetDefault <IMessagePublisher <IApplicationMessage>, ApplicationMessagePublisher>(_applicationMessagePublisher);
            }

            if (useMockPublishableExceptionPublisher)
            {
                configuration.SetDefault <IMessagePublisher <IPublishableException>, MockPublishableExceptionPublisher>();
            }
            else
            {
                configuration.SetDefault <IMessagePublisher <IPublishableException>, PublishableExceptionPublisher>(_publishableExceptionPublisher);
            }

            configuration.SetDefault <ICommandService, CommandService>(_commandService);

            _commandConsumer = new CommandConsumer(setting: new ConsumerSetting {
                ConsumeFromWhere = ConsumeFromWhere.FirstOffset
            }).Subscribe("CommandTopic");
            _eventConsumer = new DomainEventConsumer(setting: new ConsumerSetting {
                ConsumeFromWhere = ConsumeFromWhere.FirstOffset
            }).Subscribe("EventTopic");
            _applicationMessageConsumer = new ApplicationMessageConsumer(setting: new ConsumerSetting {
                ConsumeFromWhere = ConsumeFromWhere.FirstOffset
            }).Subscribe("ApplicationMessageTopic");
            _publishableExceptionConsumer = new PublishableExceptionConsumer(setting: new ConsumerSetting {
                ConsumeFromWhere = ConsumeFromWhere.FirstOffset
            }).Subscribe("PublishableExceptionTopic");

            return(enodeConfiguration);
        }
        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);
        }