コード例 #1
0
ファイル: ENodeExtensions.cs プロジェクト: zjxbetter/enode
 public static ENodeConfiguration StartEQueue(this ENodeConfiguration enodeConfiguration)
 {
     _broker.Start();
     _commandService.Start();
     _commandConsumer.Start();
     return(enodeConfiguration);
 }
コード例 #2
0
        public async Task Test1()
        {
            //Larva.MessageProcess.LoggerManager.SetLoggerProvider(new Log4NetLoggerProvider());
            var consumer = new CommandConsumer();

            consumer.Initialize(new ConsumerSettings
            {
                AmqpUri = new Uri("amqp://*****:*****@localhost/test")
            }, "MessageProcess_CommandTopic", 4, false, 1, new IInterceptor[] { new PerformanceCounterInterceptor() }, typeof(CommandTests).Assembly);
            consumer.Start();

            var commandBus = new CommandBus();

            commandBus.Initialize(new ProducerSettings
            {
                AmqpUri = new Uri("amqp://*****:*****@localhost/test")
            }, "MessageProcess_CommandTopic", 4, IPEndPoint.Parse("127.0.0.1:5000"));
            commandBus.Start();
            for (var i = 1; i <= 5; i++)
            {
                for (var j = 1; j <= 5; j++)
                {
                    await commandBus.SendAsync(new Command1($"Test{i}"));
                }
            }
            Thread.Sleep(1000);
            commandBus.Shutdown();

            Thread.Sleep(10000);
            consumer.Shutdown();
        }
コード例 #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);
            _exceptionPublisher.InitializeEQueue(producerSetting);
            _applicationMessagePublisher.InitializeEQueue(producerSetting);

            _commandConsumer   = new CommandConsumer().InitializeEQueue("ConferenceCommandConsumerGroup", consumerSetting).Subscribe(Topics.ConferenceCommandTopic);
            _eventConsumer     = new DomainEventConsumer().InitializeEQueue("ConferenceEventConsumerGroup", consumerSetting).Subscribe(Topics.ConferenceDomainEventTopic);
            _exceptionConsumer = new DomainExceptionConsumer().InitializeEQueue("ConferenceExceptionConsumerGroup", consumerSetting).Subscribe(Topics.ConferenceExceptionTopic);

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

            return(enodeConfiguration);
        }
コード例 #4
0
ファイル: ENodeExtensions.cs プロジェクト: zanderphh/Shop
        public static ENodeConfiguration StartEQueue(this ENodeConfiguration enodeConfiguration)
        {
            var nameServerEndpoint  = new IPEndPoint(SocketUtils.GetLocalIPV4(), ConfigSettings.NameServerPort);
            var nameServerEndpoints = new List <IPEndPoint> {
                nameServerEndpoint
            };

            //命令消费者
            _commandConsumer = new CommandConsumer().Initialize(setting: new ConsumerSetting
            {
                NameServerList = nameServerEndpoints
            });
            _commandConsumer.Subscribe(Topics.ShopCommandTopic);

            //事件生产者
            _eventPublisher.Initialize(new ProducerSetting
            {
                NameServerList = nameServerEndpoints
            });



            _commandConsumer.Start();
            _eventPublisher.Start();

            return(enodeConfiguration);
        }
コード例 #5
0
        public static ENodeConfiguration StartEQueue(this ENodeConfiguration enodeConfiguration)
        {
            _eventPublisher.Initialize(new ProducerSetting()
            {
                NameServerList = ServiceConfigSettings.NameServerEndpoints
            });

            _commandConsumer = new CommandConsumer().Initialize(setting: new ConsumerSetting()
            {
                NameServerList    = ServiceConfigSettings.NameServerEndpoints,
                ConsumeFromWhere  = ConsumeFromWhere.LastOffset,
                MessageHandleMode = MessageHandleMode.Parallel,
            });

            _commandConsumer
            .Subscribe(EQueueTopics.LotteryCommandTopic)
            .Subscribe(EQueueTopics.LotteryAccountCommandTopic)
            .Subscribe(EQueueTopics.LotteryProcessManagerTopic)
            .Subscribe(EQueueTopics.UserInfoCommandTopic)
            .Subscribe(EQueueTopics.NormCommandTopic)
            .Subscribe(EQueueTopics.MessageCommandTopic);

            _commandConsumer.Start();
            _eventPublisher.Start();

            return(enodeConfiguration);
        }
コード例 #6
0
ファイル: ENodeExtensions.cs プロジェクト: wangyuzhu/forum
        public static ENodeConfiguration StartEQueue(this ENodeConfiguration enodeConfiguration)
        {
            var nameServerEndpoint  = new IPEndPoint(IPAddress.Loopback, ConfigSettings.NameServerPort);
            var nameServerEndpoints = new List <IPEndPoint> {
                nameServerEndpoint
            };

            _eventPublisher.InitializeEQueue(new ProducerSetting
            {
                NameServerList = nameServerEndpoints
            });

            _commandConsumer = new CommandConsumer().InitializeEQueue(setting: new ConsumerSetting
            {
                NameServerList = nameServerEndpoints
            });
            _commandConsumer
            .Subscribe("AccountCommandTopic")
            .Subscribe("SectionCommandTopic")
            .Subscribe("PostCommandTopic")
            .Subscribe("ReplyCommandTopic");

            _commandConsumer.Start();
            _eventPublisher.Start();

            return(enodeConfiguration);
        }
コード例 #7
0
ファイル: ENodeExtensions.cs プロジェクト: zhouyu11/enode
        public static ENodeConfiguration StartEQueue(this ENodeConfiguration enodeConfiguration)
        {
            var brokerStorePath = ConfigurationManager.AppSettings["equeue-store-path"];

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

            var configuration = enodeConfiguration.GetCommonConfiguration();

            _commandService.InitializeEQueue(new CommandResultProcessor().Initialize(new IPEndPoint(SocketUtils.GetLocalIPV4(), 9000)));
            _eventPublisher.InitializeEQueue();
            _commandConsumer = new CommandConsumer().InitializeEQueue().Subscribe("NoteCommandTopic");
            _eventConsumer   = new DomainEventConsumer().InitializeEQueue().Subscribe("NoteEventTopic");

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

            _nameServerController.Start();
            _broker.Start();
            _eventConsumer.Start();
            _commandConsumer.Start();
            _eventPublisher.Start();
            _commandService.Start();

            WaitAllProducerTopicQueuesAvailable();
            WaitAllConsumerLoadBalanceComplete();

            return(enodeConfiguration);
        }
コード例 #8
0
        public static ENodeConfiguration StartEQueue(this ENodeConfiguration enodeConfiguration)
        {
            //var configuration = enodeConfiguration.GetCommonConfiguration();
            _commandService.Initialize(
                new CommandResultProcessor().Initialize(
                    new IPEndPoint(SocketUtils.GetLocalIPV4(), ConfigSettings.BrokerCommandPort)));
            _eventPublisher.Initialize();

            _commandConsumer = new CommandConsumer().Initialize().Subscribe(EQueueTopics.NoteCommandTopic);
            _eventConsumer   = new DomainEventConsumer().Initialize().Subscribe(EQueueTopics.NoteEventTopic);

            var brokerStorePath = @"d:\note-sample-equeue-store";

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

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

            _nameServer.Start();
            _broker.Start();
            _commandService.Start();
            _eventConsumer.Start();
            _commandConsumer.Start();
            _eventPublisher.Start();

            WaitAllConsumerLoadBalanceComplete();

            return(enodeConfiguration);
        }
コード例 #9
0
        public static ENodeConfiguration StartEQueue(this ENodeConfiguration enodeConfiguration)
        {
            _commandConsumer.Start();
            _domainEventPublisher.Start();
            WaitAllConsumerLoadBalanceComplete();

            return(enodeConfiguration);
        }
コード例 #10
0
 public static ENodeConfiguration StartEQueue(this ENodeConfiguration enodeConfiguration)
 {
     _eventConsumer.Start();
     _commandConsumer.Start();
     _applicationMessagePublisher.Start();
     _domainEventPublisher.Start();
     return(enodeConfiguration);
 }
コード例 #11
0
        public void Start(out string errMsg)
        {
            errMsg = "";
            if (IsRuning)
            {
                return;
            }

            // 环境检查
            if (!EnvChecker.CheckPandaYaLiWEB(out errMsg))
            {
                return;
            }
            TraceManagerForWeb.AppendDebug("Scada-WEB-压力监测点环境检查通过");
            this.param = Config.pandaYaLiParam;

            WebPandaYLScadaCommand.CreateInitSensorRealData(param).Execute(); //初始化实时表

            timer          = new System.Timers.Timer();
            timer.Interval = this.param.collectInterval * 60 * 1000;
            timer.Elapsed += (o, e) =>
            {
                try
                {
                    Excute();
                }
                catch (Exception ee)
                {
                    TraceManagerForWeb.AppendErrMsg("Scada-WEB-压力监测点定时任务执行失败:" + ee.Message);
                }
            };
            timer.Enabled = true;

            // 控制器服务
            if (commandCustomer != null)
            {
                commandCustomer.Stop();
            }
            commandCustomer = new CommandConsumer(ConsumerCommand);
            commandCustomer.Start();
            if (commandCustomer.IsRuning)
            {
                TraceManagerForWeb.AppendDebug("Scada-WEB-压力监测点控制器服务已经打开");
            }
            else
            {
                TraceManagerForWeb.AppendErrMsg("Scada-WEB-压力监测点控制器服务打开失败");
                Stop();
                return;
            }

            IsRuning = true;

            // 开始异步执行一次-防止启动卡死
            Action action = Excute;

            action.BeginInvoke(null, null);
        }
コード例 #12
0
ファイル: ENodeExtensions.cs プロジェクト: tangruixing/enode
        public static ENodeConfiguration StartEQueue(this ENodeConfiguration enodeConfiguration)
        {
            _broker.Start();
            _eventConsumer.Start();
            _commandConsumer.Start();
            _eventPublisher.Start();
            _commandService.Start();

            WaitAllConsumerLoadBalanceComplete();

            return(enodeConfiguration);
        }
コード例 #13
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);
        }
コード例 #14
0
ファイル: XingGuoService.cs プロジェクト: Jaasdsa/CityIoT
        public override void Start(out string errMsg)
        {
            errMsg = "";
            if (IsRuning)
            {
                return;
            }

            WEBSoapCommand.CreateInitSensorRealData(param).Execute(); //初始化实时表

            timer          = new System.Timers.Timer();
            timer.Interval = this.param.collectInterval * 1000;
            timer.Elapsed += (o, e) =>
            {
                try
                {
                    Excute();
                }
                catch (Exception ee)
                {
                    TraceManagerForProject.AppendErrMsg("WEB-SOAP-兴国定时任务执行失败:" + ee.Message);
                }
            };
            timer.Enabled = true;

            // 控制器服务
            if (commandCustomer != null)
            {
                commandCustomer.Stop();
            }
            commandCustomer = new CommandConsumer(ConsumerCommand);
            commandCustomer.Start();
            if (commandCustomer.IsRuning)
            {
                TraceManagerForProject.AppendDebug("WEB-SOAP-兴国控制器服务已经打开");
            }
            else
            {
                TraceManagerForProject.AppendErrMsg("WEB-SOAP-兴国控制器服务打开失败");
                Stop();
                return;
            }

            IsRuning = true;

            // 开始异步执行一次-防止启动卡死
            Action action = Excute;

            action.BeginInvoke(null, null);
        }
コード例 #15
0
ファイル: ENodeExtensions.cs プロジェクト: vebin/NCas
        public static ENodeConfiguration StartEQueue(this ENodeConfiguration enodeConfiguration)
        {
            _exceptionConsumer.Start();
            _eventConsumer.Start();
            _applicationMessageConsumer.Start();
            _commandConsumer.Start();
            _applicationMessagePublisher.Start();
            _domainEventPublisher.Start();
            _exceptionPublisher.Start();

            WaitAllConsumerLoadBalanceComplete();

            return(enodeConfiguration);
        }
コード例 #16
0
 public static ENodeConfiguration StartEQueue(this ENodeConfiguration enodeConfiguration)
 {
     _nameServerController.Start();
     _broker.Start();
     _eventConsumer.Start();
     _commandConsumer.Start();
     _applicationMessageConsumer.Start();
     _publishableExceptionConsumer.Start();
     _applicationMessagePublisher.Start();
     _publishableExceptionPublisher.Start();
     _eventPublisher.Start();
     _commandService.Start();
     WaitAllConsumerLoadBalanceComplete();
     return(enodeConfiguration);
 }
コード例 #17
0
        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);
        }
コード例 #18
0
ファイル: ENodeExtensions.cs プロジェクト: xw-ASample/enode
        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);
        }
コード例 #19
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);
        }
コード例 #20
0
        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);
        }
コード例 #21
0
        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);
        }
コード例 #22
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);
        }
コード例 #23
0
ファイル: ENodeExtensions.cs プロジェクト: wangyuzhu/forum
        public static ENodeConfiguration StartEQueue(this ENodeConfiguration enodeConfiguration)
        {
            if (_isEQueueStarted)
            {
                _commandService.InitializeENode();
                _eventPublisher.InitializeENode();

                _commandConsumer.InitializeENode();
                _eventConsumer.InitializeENode();

                return(enodeConfiguration);
            }

            var nameServerEndpoint  = new IPEndPoint(IPAddress.Loopback, ConfigSettings.NameServerPort);
            var nameServerEndpoints = new List <IPEndPoint> {
                nameServerEndpoint
            };
            var nameServerSetting = new NameServerSetting()
            {
                BindingAddress = nameServerEndpoint
            };

            _nameServerController = new NameServerController(nameServerSetting);

            var brokerStorePath = @"d:\forum-equeue-store-test";

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

            var brokerSetting = new BrokerSetting(false, brokerStorePath)
            {
                NameServerList = nameServerEndpoints
            };

            brokerSetting.BrokerInfo.ProducerAddress = new IPEndPoint(IPAddress.Loopback, ConfigSettings.BrokerProducerPort).ToAddress();
            brokerSetting.BrokerInfo.ConsumerAddress = new IPEndPoint(IPAddress.Loopback, ConfigSettings.BrokerConsumerPort).ToAddress();
            brokerSetting.BrokerInfo.AdminAddress    = new IPEndPoint(IPAddress.Loopback, ConfigSettings.BrokerAdminPort).ToAddress();
            _broker = BrokerController.Create(brokerSetting);

            _commandService.InitializeEQueue(new CommandResultProcessor().Initialize(new IPEndPoint(IPAddress.Loopback, 9000)), new ProducerSetting
            {
                NameServerList = nameServerEndpoints
            });
            _eventPublisher.InitializeEQueue(new ProducerSetting
            {
                NameServerList = nameServerEndpoints
            });
            _commandConsumer = new CommandConsumer().InitializeEQueue(setting: new ConsumerSetting
            {
                NameServerList = nameServerEndpoints
            });
            _eventConsumer = new DomainEventConsumer().InitializeEQueue(setting: new ConsumerSetting
            {
                NameServerList = nameServerEndpoints
            });

            _commandConsumer
            .Subscribe("AccountCommandTopic")
            .Subscribe("SectionCommandTopic")
            .Subscribe("PostCommandTopic")
            .Subscribe("ReplyCommandTopic");
            _eventConsumer
            .Subscribe("AccountEventTopic")
            .Subscribe("SectionEventTopic")
            .Subscribe("PostEventTopic")
            .Subscribe("ReplyEventTopic");

            _nameServerController.Start();
            _broker.Start();
            _eventConsumer.Start();
            _commandConsumer.Start();
            _eventPublisher.Start();
            _commandService.Start();

            WaitAllConsumerLoadBalanceComplete();

            _isEQueueStarted = true;

            return(enodeConfiguration);
        }
コード例 #24
0
        static void Main(string[] args)
        {
            try
            {
                Configuration.Instance.UseLog4Net()
                .RegisterMessageContextType(typeof(IFramework.MessageQueue.EQueue.MessageFormat.MessageContext))
                .InitliaizeEQueue(5000, 5001, 5000)
                .CommandHandlerProviderBuild(null, "CommandHandlers");

                var consumerSetting = new ConsumerSetting();
                consumerSetting.MessageHandleMode = MessageHandleMode.Sequential;
                consumerSetting.BrokerPort        = 5001;

                var producerSetting = new ProducerSetting();
                var producerPort    = producerSetting.BrokerPort = 5000;

                var eventHandlerProvider = IoCFactory.Resolve <IHandlerProvider>("AsyncDomainEventSubscriber");
                IMessageConsumer domainEventSubscriber = new DomainEventSubscriber("domainEventSubscriber1",
                                                                                   consumerSetting,
                                                                                   "DomainEventSubscriber",
                                                                                   "domainevent",
                                                                                   eventHandlerProvider);
                domainEventSubscriber.Start();
                IoCFactory.Instance.CurrentContainer.RegisterInstance("DomainEventConsumer", domainEventSubscriber);

                IEventPublisher eventPublisher = new EventPublisher("EventPublisher", "domainevent",
                                                                    producerSetting);
                IoCFactory.Instance.CurrentContainer.RegisterInstance(typeof(IEventPublisher),
                                                                      eventPublisher,
                                                                      new ContainerControlledLifetimeManager());


                var commandHandlerProvider = IoCFactory.Resolve <ICommandHandlerProvider>();
                var commandConsumer1       = new CommandConsumer("consumer1", consumerSetting,
                                                                 "CommandConsumerGroup",
                                                                 "Command",
                                                                 consumerSetting.BrokerAddress,
                                                                 producerPort,
                                                                 commandHandlerProvider);

                var commandConsumer2 = new CommandConsumer("consumer2", consumerSetting,
                                                           "CommandConsumerGroup",
                                                           "Command",
                                                           consumerSetting.BrokerAddress,
                                                           producerPort,
                                                           commandHandlerProvider);

                var commandConsumer3 = new CommandConsumer("consumer3", consumerSetting,
                                                           "CommandConsumerGroup",
                                                           "Command",
                                                           consumerSetting.BrokerAddress,
                                                           producerPort,
                                                           commandHandlerProvider);

                var commandConsumer4 = new CommandConsumer("consumer4", consumerSetting,
                                                           "CommandConsumerGroup",
                                                           "Command",
                                                           consumerSetting.BrokerAddress,
                                                           producerPort,
                                                           commandHandlerProvider);

                commandConsumer1.Start();
                commandConsumer2.Start();
                commandConsumer3.Start();
                commandConsumer4.Start();

                commandBus = new CommandBus("CommandBus",
                                            commandHandlerProvider,
                                            IoCFactory.Resolve <ILinearCommandManager>(),
                                            consumerSetting.BrokerAddress,
                                            producerPort,
                                            consumerSetting,
                                            "CommandBus",
                                            "Reply",
                                            "Command",
                                            true);

                IoCFactory.Instance.CurrentContainer.RegisterInstance(typeof(ICommandBus),
                                                                      commandBus,
                                                                      new ContainerControlledLifetimeManager());
                commandBus.Start();

                //Below to wait for consumer balance.
                var scheduleService = ObjectContainer.Resolve <IScheduleService>();
                var waitHandle      = new ManualResetEvent(false);
                var taskId          = scheduleService.ScheduleTask("consumer logs", () =>
                {
                    var bAllocatedQueueIds  = (commandBus as CommandBus).Consumer.GetCurrentQueues().Select(x => x.QueueId);
                    var c1AllocatedQueueIds = commandConsumer1.Consumer.GetCurrentQueues().Select(x => x.QueueId);
                    var c2AllocatedQueueIds = commandConsumer2.Consumer.GetCurrentQueues().Select(x => x.QueueId);
                    var c3AllocatedQueueIds = commandConsumer3.Consumer.GetCurrentQueues().Select(x => x.QueueId);
                    var c4AllocatedQueueIds = commandConsumer4.Consumer.GetCurrentQueues().Select(x => x.QueueId);
                    var eAllocatedQueueIds  = (domainEventSubscriber as DomainEventSubscriber).Consumer.GetCurrentQueues().Select(x => x.QueueId);

                    Console.WriteLine(string.Format("Consumer message queue allocation result:bus:{0}, eventSubscriber:{1} c1:{2}, c2:{3}, c3:{4}, c4:{5}",
                                                    string.Join(",", bAllocatedQueueIds),
                                                    string.Join(",", eAllocatedQueueIds),
                                                    string.Join(",", c1AllocatedQueueIds),
                                                    string.Join(",", c2AllocatedQueueIds),
                                                    string.Join(",", c3AllocatedQueueIds),
                                                    string.Join(",", c4AllocatedQueueIds)));

                    if (eAllocatedQueueIds.Count() == 4 &&
                        bAllocatedQueueIds.Count() == 4 &&
                        c1AllocatedQueueIds.Count() == 1 &&
                        c2AllocatedQueueIds.Count() == 1 &&
                        c3AllocatedQueueIds.Count() == 1 &&
                        c4AllocatedQueueIds.Count() == 1)
                    {
                        waitHandle.Set();
                    }
                }, 1000, 1000);

                waitHandle.WaitOne();
                scheduleService.ShutdownTask(taskId);

                var worker = new Worker(commandBus);
                //worker.StartTest(100);


                while (true)
                {
                    Console.WriteLine(CommandConsumer.GetConsumersStatus());
                    Console.WriteLine(domainEventSubscriber.GetStatus());
                    Console.WriteLine("please input batch count and rerun another test:");
                    var input      = Console.ReadLine();
                    var batchCount = 0;
                    if (int.TryParse(input, out batchCount))
                    {
                        worker.StartTest(batchCount);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.GetBaseException().Message, ex);
            }
            finally
            {
                Console.Read();
            }
        }
コード例 #25
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);
        }
コード例 #26
0
 public static ENodeConfiguration StartEQueue(this ENodeConfiguration enodeConfiguration)
 {
     _commandConsumer.Start();
     _eventPublisher.Start();
     return(enodeConfiguration);
 }
コード例 #27
0
ファイル: Program.cs プロジェクト: vebin/IFramework
        static void Main(string[] args)
        {
            try
            {

                Configuration.Instance.UseLog4Net()
                                      .RegisterMessageContextType(typeof(IFramework.MessageQueue.EQueue.MessageFormat.MessageContext))
                                      .InitliaizeEQueue(5000, 5001, 5000)
                                      .CommandHandlerProviderBuild(null, "CommandHandlers");

                var consumerSetting = new ConsumerSetting();
                consumerSetting.MessageHandleMode = MessageHandleMode.Sequential;
                consumerSetting.BrokerPort = 5001;

                var producerSetting = new ProducerSetting();
                var producerPort = producerSetting.BrokerPort = 5000;

                var eventHandlerProvider = IoCFactory.Resolve<IHandlerProvider>("AsyncDomainEventSubscriber");
                IMessageConsumer domainEventSubscriber = new DomainEventSubscriber("domainEventSubscriber1",
                                                                                   consumerSetting,
                                                                                   "DomainEventSubscriber",
                                                                                   "domainevent",
                                                                                   eventHandlerProvider);
                domainEventSubscriber.Start();
                IoCFactory.Instance.CurrentContainer.RegisterInstance("DomainEventConsumer", domainEventSubscriber);

                IEventPublisher eventPublisher = new EventPublisher("EventPublisher", "domainevent",
                                                                  producerSetting);
                IoCFactory.Instance.CurrentContainer.RegisterInstance(typeof(IEventPublisher),
                                                                      eventPublisher,
                                                                      new ContainerControlledLifetimeManager());

                var commandHandlerProvider = IoCFactory.Resolve<ICommandHandlerProvider>();
                var commandConsumer1 = new CommandConsumer("consumer1", consumerSetting,
                                                           "CommandConsumerGroup",
                                                           "Command",
                                                           consumerSetting.BrokerAddress,
                                                           producerPort,
                                                           commandHandlerProvider);

                var commandConsumer2 = new CommandConsumer("consumer2", consumerSetting,
                                                           "CommandConsumerGroup",
                                                           "Command",
                                                           consumerSetting.BrokerAddress,
                                                           producerPort,
                                                           commandHandlerProvider);

                var commandConsumer3 = new CommandConsumer("consumer3", consumerSetting,
                                                           "CommandConsumerGroup",
                                                           "Command",
                                                           consumerSetting.BrokerAddress,
                                                           producerPort,
                                                           commandHandlerProvider);

                var commandConsumer4 = new CommandConsumer("consumer4", consumerSetting,
                                                          "CommandConsumerGroup",
                                                          "Command",
                                                          consumerSetting.BrokerAddress,
                                                          producerPort,
                                                          commandHandlerProvider);

                commandConsumer1.Start();
                commandConsumer2.Start();
                commandConsumer3.Start();
                commandConsumer4.Start();

                commandBus = new CommandBus("CommandBus",
                                                        commandHandlerProvider,
                                                        IoCFactory.Resolve<ILinearCommandManager>(),
                                                        consumerSetting.BrokerAddress,
                                                        producerPort,
                                                        consumerSetting,
                                                        "CommandBus",
                                                        "Reply",
                                                        "Command",
                                                        true);

                IoCFactory.Instance.CurrentContainer.RegisterInstance(typeof(ICommandBus),
                                                                      commandBus,
                                                                      new ContainerControlledLifetimeManager());
                commandBus.Start();

                //Below to wait for consumer balance.
                var scheduleService = ObjectContainer.Resolve<IScheduleService>();
                var waitHandle = new ManualResetEvent(false);
                var taskId = scheduleService.ScheduleTask("consumer logs", () =>
                {
                    var bAllocatedQueueIds = (commandBus as CommandBus).Consumer.GetCurrentQueues().Select(x => x.QueueId);
                    var c1AllocatedQueueIds = commandConsumer1.Consumer.GetCurrentQueues().Select(x => x.QueueId);
                    var c2AllocatedQueueIds = commandConsumer2.Consumer.GetCurrentQueues().Select(x => x.QueueId);
                    var c3AllocatedQueueIds = commandConsumer3.Consumer.GetCurrentQueues().Select(x => x.QueueId);
                    var c4AllocatedQueueIds = commandConsumer4.Consumer.GetCurrentQueues().Select(x => x.QueueId);
                    var eAllocatedQueueIds = (domainEventSubscriber as DomainEventSubscriber).Consumer.GetCurrentQueues().Select(x => x.QueueId);

                    Console.WriteLine(string.Format("Consumer message queue allocation result:bus:{0}, eventSubscriber:{1} c1:{2}, c2:{3}, c3:{4}, c4:{5}",
                          string.Join(",", bAllocatedQueueIds),
                          string.Join(",", eAllocatedQueueIds),
                          string.Join(",", c1AllocatedQueueIds),
                          string.Join(",", c2AllocatedQueueIds),
                          string.Join(",", c3AllocatedQueueIds),
                          string.Join(",", c4AllocatedQueueIds)));

                    if (eAllocatedQueueIds.Count() == 4
                        && bAllocatedQueueIds.Count() == 4
                        && c1AllocatedQueueIds.Count() == 1
                        && c2AllocatedQueueIds.Count() == 1
                        && c3AllocatedQueueIds.Count() == 1
                        && c4AllocatedQueueIds.Count() == 1)
                    {

                        waitHandle.Set();
                    }
                }, 1000, 1000);

                waitHandle.WaitOne();
                scheduleService.ShutdownTask(taskId);

                var worker = new Worker(commandBus);
                //worker.StartTest(100);

                while (true)
                {
                    Console.WriteLine(CommandConsumer.GetConsumersStatus());
                    Console.WriteLine(domainEventSubscriber.GetStatus());
                    Console.WriteLine("please input batch count and rerun another test:");
                    var input = Console.ReadLine();
                    var batchCount = 0;
                    if (int.TryParse(input, out batchCount))
                    {
                        worker.StartTest(batchCount);
                    }
                }

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.GetBaseException().Message, ex);
            }
            finally
            {
                Console.Read();
            }
        }
コード例 #28
0
ファイル: ENodeExtensions.cs プロジェクト: xDaWenXi/enode
        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);
        }
コード例 #29
0
        public static ENodeConfiguration StartEQueue(this ENodeConfiguration enodeConfiguration)
        {
            var nameServerSetting = new NameServerSetting()
            {
                BindingAddress = ServiceConfigSettings.NameServerAddress
            };

            _nameServer = new NameServerController(nameServerSetting);

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

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

            var brokerSetting = new BrokerSetting(false, brokerStorePath)
            {
                NameServerList = ServiceConfigSettings.NameServerEndpoints,
            };

            brokerSetting.BrokerInfo.ProducerAddress = ServiceConfigSettings.BrokerProducerServiceAddress;
            brokerSetting.BrokerInfo.ConsumerAddress = ServiceConfigSettings.BrokerConsumerServiceAddress;
            brokerSetting.BrokerInfo.AdminAddress    = ServiceConfigSettings.BrokerAdminServiceAddress;
            _broker = BrokerController.Create(brokerSetting);

            _commandService.Initialize(new CommandResultProcessor().Initialize(new IPEndPoint(IPAddress.Loopback, 9000)), new ProducerSetting
            {
                NameServerList = ServiceConfigSettings.NameServerEndpoints,
            });
            _eventPublisher.Initialize(new ProducerSetting
            {
                NameServerList = ServiceConfigSettings.NameServerEndpoints
            });
            _commandConsumer = new CommandConsumer().Initialize(setting: new ConsumerSetting
            {
                NameServerList           = ServiceConfigSettings.NameServerEndpoints,
                ConsumeFromWhere         = ConsumeFromWhere.LastOffset,
                MessageHandleMode        = MessageHandleMode.Sequential,
                IgnoreLastConsumedOffset = true,
                AutoPull = true
            });
            _eventConsumer = new DomainEventConsumer().Initialize(setting: new ConsumerSetting
            {
                NameServerList           = ServiceConfigSettings.NameServerEndpoints,
                ConsumeFromWhere         = ConsumeFromWhere.LastOffset,
                MessageHandleMode        = MessageHandleMode.Sequential,
                IgnoreLastConsumedOffset = true,
                AutoPull = true
            });

            _commandConsumer
            .Subscribe(EQueueTopics.LotteryCommandTopic)
            .Subscribe(EQueueTopics.LotteryAccountCommandTopic)
            .Subscribe(EQueueTopics.NormCommandTopic)
            ;

            _eventConsumer
            .Subscribe(EQueueTopics.LotteryEventTopic)
            .Subscribe(EQueueTopics.LotteryAccountEventTopic)
            .Subscribe(EQueueTopics.NormEventTopic);

            _nameServer.Start();
            _broker.Start();
            _eventConsumer.Start();
            _commandConsumer.Start();
            _eventPublisher.Start();
            _commandService.Start();

            //  WaitAllConsumerLoadBalanceComplete();

            return(enodeConfiguration);
        }