public static ENodeConfiguration UseEQueue(this ENodeConfiguration enodeConfiguration) { var configuration = enodeConfiguration.GetCommonConfiguration(); configuration.RegisterEQueueComponents(); var consumerSetting = new ConsumerSetting { HeartbeatBrokerInterval = 1000, UpdateTopicQueueCountInterval = 1000, RebalanceInterval = 1000 }; _commandExecutedMessageSender = new CommandExecutedMessageSender(); _eventPublisher = new EventPublisher(); configuration.SetDefault<IEventPublisher, EventPublisher>(_eventPublisher); _commandConsumer = new CommandConsumer(consumerSetting, _commandExecutedMessageSender); _commandConsumer.Subscribe("NoteCommandTopic1"); _commandConsumer.Subscribe("NoteCommandTopic2"); return enodeConfiguration; }
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); }
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(); }
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); }
public static ENodeConfiguration UseEQueue(this ENodeConfiguration enodeConfiguration) { var configuration = enodeConfiguration.GetCommonConfiguration(); var brokerStorePath = @"c:\equeue-store"; if (Directory.Exists(brokerStorePath)) { Directory.Delete(brokerStorePath, true); } configuration.RegisterEQueueComponents(); _nameServerController = new NameServerController(); _broker = BrokerController.Create(); _commandResultProcessor = new CommandResultProcessor(new IPEndPoint(SocketUtils.GetLocalIPV4(), 9000)); _commandService = new CommandService(_commandResultProcessor); _eventPublisher = new DomainEventPublisher(); configuration.SetDefault <ICommandService, CommandService>(_commandService); configuration.SetDefault <IMessagePublisher <DomainEventStreamMessage>, DomainEventPublisher>(_eventPublisher); //注意,这里实例化之前,需要确保各种MessagePublisher要先注入到IOC,因为CommandConsumer, DomainEventConsumer都依赖于IMessagePublisher<T> _commandConsumer = new CommandConsumer(); _eventConsumer = new DomainEventConsumer(); _commandConsumer.Subscribe("NoteCommandTopic"); _eventConsumer.Subscribe("NoteEventTopic"); return(enodeConfiguration); }
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; }
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); }
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); _eventPublisher = new DomainEventPublisher(); configuration.SetDefault<ICommandService, CommandService>(_commandService); configuration.SetDefault<IMessagePublisher<DomainEventStreamMessage>, DomainEventPublisher>(_eventPublisher); //注意,这里实例化之前,需要确保各种MessagePublisher要先注入到IOC,因为CommandConsumer, DomainEventConsumer都依赖于IMessagePublisher<T> _commandConsumer = new CommandConsumer(); _eventConsumer = new DomainEventConsumer(); _commandConsumer.Subscribe("NoteCommandTopic"); _eventConsumer.Subscribe("NoteEventTopic"); return enodeConfiguration; }
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); }
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) }; _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("ConferenceCommandConsumerGroup", consumerSetting).Subscribe(Topics.ConferenceCommandTopic); _eventConsumer = new DomainEventConsumer("ConferenceEventConsumerGroup", consumerSetting).Subscribe(Topics.ConferenceDomainEventTopic); _exceptionConsumer = new PublishableExceptionConsumer("ConferenceExceptionConsumerGroup", consumerSetting).Subscribe(Topics.ConferenceExceptionTopic); return(enodeConfiguration); }
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); }
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; }
public static ENodeConfiguration UseEQueue(this ENodeConfiguration enodeConfiguration) { var configuration = enodeConfiguration.GetCommonConfiguration(); configuration.RegisterEQueueComponents(); _broker = new BrokerController(); _commandResultProcessor = new CommandResultProcessor(); _commandService = new CommandService(_commandResultProcessor); _eventPublisher = new DomainEventPublisher(); configuration.SetDefault <ICommandService, CommandService>(_commandService); configuration.SetDefault <IMessagePublisher <DomainEventStreamMessage>, DomainEventPublisher>(_eventPublisher); _commandConsumer = new CommandConsumer(); _eventConsumer = new DomainEventConsumer(); _commandConsumer .Subscribe("AccountCommandTopic") .Subscribe("SectionCommandTopic") .Subscribe("PostCommandTopic") .Subscribe("ReplyCommandTopic"); _eventConsumer .Subscribe("AccountEventTopic") .Subscribe("SectionEventTopic") .Subscribe("PostEventTopic") .Subscribe("ReplyEventTopic"); return(enodeConfiguration); }
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); }
public static ENodeConfiguration UseEQueue(this ENodeConfiguration enodeConfiguration) { var configuration = enodeConfiguration.GetCommonConfiguration(); configuration.RegisterEQueueComponents(); var nameServerEndpoint = new IPEndPoint(IPAddress.Loopback, ConfigSettings.NameServerPort); var nameServerEndpoints = new List <IPEndPoint> { nameServerEndpoint }; _eventPublisher = new DomainEventPublisher(new ProducerSetting { NameServerList = nameServerEndpoints }); configuration.SetDefault <IMessagePublisher <DomainEventStreamMessage>, DomainEventPublisher>(_eventPublisher); _commandConsumer = new CommandConsumer(setting: new ConsumerSetting { NameServerList = nameServerEndpoints }); _commandConsumer .Subscribe("AccountCommandTopic") .Subscribe("SectionCommandTopic") .Subscribe("PostCommandTopic") .Subscribe("ReplyCommandTopic"); return(enodeConfiguration); }
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) } }; _applicationMessagePublisher = new ApplicationMessagePublisher(producerSetting); _domainEventPublisher = new DomainEventPublisher(producerSetting); configuration.SetDefault <IMessagePublisher <IApplicationMessage>, ApplicationMessagePublisher>(_applicationMessagePublisher); configuration.SetDefault <IMessagePublisher <DomainEventStreamMessage>, DomainEventPublisher>(_domainEventPublisher); _commandConsumer = new CommandConsumer("PaymentCommandConsumerGroup", consumerSetting).Subscribe(Topics.PaymentCommandTopic); _eventConsumer = new DomainEventConsumer("PaymentEventConsumerGroup", consumerSetting).Subscribe(Topics.PaymentDomainEventTopic); return(enodeConfiguration); }
public static ENodeConfiguration UseEQueue(this ENodeConfiguration enodeConfiguration) { var configuration = enodeConfiguration.GetCommonConfiguration(); configuration.RegisterEQueueComponents(); var producerSetting = new ProducerSetting { BrokerAddress = new IPEndPoint(SocketUtils.GetLocalIPV4(), PortConfiguration.BrokerProducerPort), BrokerAdminAddress = new IPEndPoint(SocketUtils.GetLocalIPV4(), PortConfiguration.BrokerAdminPort) }; var consumerSetting = new ConsumerSetting { BrokerAddress = new IPEndPoint(SocketUtils.GetLocalIPV4(), PortConfiguration.BrokerConsumerPort), BrokerAdminAddress = new IPEndPoint(SocketUtils.GetLocalIPV4(), PortConfiguration.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(setting: consumerSetting).Subscribe(TopicConfiguration.AccountCommandTopic); _eventConsumer = new DomainEventConsumer(setting: consumerSetting).Subscribe(TopicConfiguration.AccountDomainEventTopic); _exceptionConsumer = new PublishableExceptionConsumer(setting: consumerSetting).Subscribe(TopicConfiguration.AccountExceptionTopic); return enodeConfiguration; }
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); }
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); }
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); }
public static ENodeConfiguration UseEQueue(this ENodeConfiguration enodeConfiguration) { var configuration = enodeConfiguration.GetCommonConfiguration(); var brokerStorePath = @"c:\person-equeue-store-test"; if (Directory.Exists(brokerStorePath)) { Directory.Delete(brokerStorePath, true); } configuration.RegisterEQueueComponents(); var nameServerEndpoint = new IPEndPoint(IPAddress.Loopback, ConfigSettings.NameServerPort); var nameServerEndpoints = new List <IPEndPoint> { nameServerEndpoint }; var nameServerSetting = new NameServerSetting() { BindingAddress = nameServerEndpoint }; _nameServer = new NameServerController(nameServerSetting); var brokerSetting = new BrokerSetting(false, brokerStorePath); brokerSetting.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); var producerSetting = new ProducerSetting { NameServerList = new List <IPEndPoint> { new IPEndPoint(IPAddress.Loopback, ConfigSettings.NameServerPort) } }; var consumerSetting = new ConsumerSetting { NameServerList = new List <IPEndPoint> { new IPEndPoint(IPAddress.Loopback, ConfigSettings.NameServerPort) } }; _commandResultProcessor = new CommandResultProcessor(new IPEndPoint(IPAddress.Loopback, 9003)); _commandService = new CommandService(_commandResultProcessor, producerSetting); _eventPublisher = new DomainEventPublisher(producerSetting); configuration.SetDefault <ICommandService, CommandService>(_commandService); configuration.SetDefault <IMessagePublisher <DomainEventStreamMessage>, DomainEventPublisher>(_eventPublisher); _commandConsumer = new CommandConsumer(setting: consumerSetting) .Subscribe(Topics.PersonCommandTopic); _eventConsumer = new DomainEventConsumer(setting: consumerSetting) .Subscribe(Topics.PersonDomainEventTopic); return(enodeConfiguration); }
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 IMessageConsumer CreateCommandConsumer(string commandQueue, string consumerId, params string[] handlerProvierNames) { var container = IoCFactory.Instance.CurrentContainer; var messagePublisher = container.Resolve <IMessagePublisher>(); var handlerProvider = new CommandHandlerProvider(handlerProvierNames); var messageQueueClient = IoCFactory.Resolve <IMessageQueueClient>(); var commandConsumer = new CommandConsumer(messageQueueClient, messagePublisher, handlerProvider, commandQueue, consumerId); return(commandConsumer); }
public static ENodeConfiguration UseEQueue(this ENodeConfiguration enodeConfiguration) { var configuration = enodeConfiguration.GetCommonConfiguration(); configuration.RegisterEQueueComponents(); _broker = BrokerController.Create(); _commandService = new CommandService(new CommandResultProcessor(new IPEndPoint(SocketUtils.GetLocalIPV4(), 9001))); configuration.SetDefault<ICommandService, CommandService>(_commandService); _commandConsumer = new CommandConsumer(setting: new ConsumerSetting { ConsumeFromWhere = ConsumeFromWhere.FirstOffset }).Subscribe("NoteCommandTopic"); return enodeConfiguration; }
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); }
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 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); }
public static ENodeConfiguration UseEQueue(this ENodeConfiguration enodeConfiguration) { var configuration = enodeConfiguration.GetCommonConfiguration(); configuration.RegisterEQueueComponents(); _broker = BrokerController.Create(); _commandService = new CommandService(new CommandResultProcessor(new IPEndPoint(SocketUtils.GetLocalIPV4(), 9001))); configuration.SetDefault <ICommandService, CommandService>(_commandService); _commandConsumer = new CommandConsumer(setting: new ConsumerSetting { ConsumeFromWhere = ConsumeFromWhere.FirstOffset }).Subscribe("NoteCommandTopic"); return(enodeConfiguration); }
public static ENodeConfiguration UseEQueue(this ENodeConfiguration enodeConfiguration) { var configuration = enodeConfiguration.GetCommonConfiguration(); configuration.RegisterEQueueComponents(); _domainEventPublisher = new DomainEventPublisher(); configuration.SetDefault <IMessagePublisher <DomainEventStreamMessage>, DomainEventPublisher>(_domainEventPublisher); _commandConsumer = new CommandConsumer(); _commandConsumer.Subscribe("NoteCommandTopic1"); _commandConsumer.Subscribe("NoteCommandTopic2"); return(enodeConfiguration); }
public static ENodeConfiguration UseEQueue(this ENodeConfiguration enodeConfiguration) { var configuration = enodeConfiguration.GetCommonConfiguration(); configuration.RegisterEQueueComponents(); _eventPublisher = new EventPublisher(); configuration.SetDefault<IPublisher<EventStream>, EventPublisher>(_eventPublisher); configuration.SetDefault<IPublisher<DomainEventStream>, EventPublisher>(_eventPublisher); configuration.SetDefault<IPublisher<IEvent>, EventPublisher>(_eventPublisher); _commandConsumer = new CommandConsumer(); ObjectContainer.Resolve<ITopicProvider<ICommand>>().GetAllTopics().ForEach(topic => _commandConsumer.Subscribe(topic)); return enodeConfiguration; }
public static ENodeConfiguration UseEQueue(this ENodeConfiguration enodeConfiguration) { var configuration = enodeConfiguration.GetCommonConfiguration(); configuration.RegisterEQueueComponents(); _domainEventPublisher = new DomainEventPublisher(); configuration.SetDefault<IMessagePublisher<DomainEventStreamMessage>, DomainEventPublisher>(_domainEventPublisher); _commandConsumer = new CommandConsumer(); _commandConsumer.Subscribe("NoteCommandTopic1"); _commandConsumer.Subscribe("NoteCommandTopic2"); 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); }
public Task CommandResult_NotRequired() { return(CommandConsumer.Test( async c => { c.Build(); var domainEventSrv = c.Services.Resolve <IMessagingService>(); var evt = new MockCommandNoResult(); await domainEventSrv.PublishAsync(evt); }, (IAppContainer c) => { var consumer = c.Services.Resolve <MockCommandConsumer>(); consumer.ExecutedHandlers.Should().HaveCount(1); consumer.ExecutedHandlers.Should().Contain("OnCommandNoResult"); })); }
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); }
public static ENodeConfiguration UseEQueue(this ENodeConfiguration enodeConfiguration) { var configuration = enodeConfiguration.GetCommonConfiguration(); configuration.RegisterEQueueComponents(); var producerSetting = new ProducerSetting { BrokerProducerIPEndPoint = new IPEndPoint(SocketUtils.GetLocalIPV4(), ConfigSettings.BrokerProducerPort) }; var consumerSetting = new ConsumerSetting { BrokerConsumerIPEndPoint = new IPEndPoint(SocketUtils.GetLocalIPV4(), ConfigSettings.BrokerConsumerPort) }; _domainEventPublisher = new DomainEventPublisher("RegistrationDomainEventPublisher", producerSetting); configuration.SetDefault <IMessagePublisher <DomainEventStreamMessage>, DomainEventPublisher>(_domainEventPublisher); _commandService = new CommandService(null, "RegistrationCommandService", producerSetting); configuration.SetDefault <ICommandService, CommandService>(_commandService); _commandConsumer = new CommandConsumer( "RegistrationCommandConsumer", "RegistrationCommandConsumerGroup", consumerSetting) .Subscribe(Topics.RegistrationCommandTopic); _eventConsumer = new DomainEventConsumer( "RegistrationEventConsumer", "RegistrationEventConsumerGroup", consumerSetting) .Subscribe(Topics.RegistrationDomainEventTopic); _applicationMessageConsumer = new ApplicationMessageConsumer( "RegistrationMessageConsumer", "RegistrationMessageConsumerGroup", consumerSetting) .Subscribe(Topics.ConferenceApplicationMessageTopic) .Subscribe(Topics.PaymentApplicationMessageTopic); return(enodeConfiguration); }
public static ENodeConfiguration UseEQueue(this ENodeConfiguration enodeConfiguration) { var configuration = enodeConfiguration.GetCommonConfiguration(); string dbConfig = System.Configuration.ConfigurationManager.ConnectionStrings["IntDbConn"].ConnectionString; var messageStoreSetting = new SqlServerMessageStoreSetting { ConnectionString = dbConfig, DeleteMessageHourOfDay = -1 }; var offsetManagerSetting = new SqlServerOffsetManagerSetting { ConnectionString = dbConfig }; configuration .RegisterEQueueComponents() .UseSqlServerMessageStore(messageStoreSetting) .UseSqlServerOffsetManager(offsetManagerSetting); _broker = new BrokerController(); _commandResultProcessor = new CommandResultProcessor(); _commandService = new CommandService(_commandResultProcessor); _eventPublisher = new EventPublisher(); configuration.SetDefault<ICommandService, CommandService>(_commandService); configuration.SetDefault<IPublisher<EventStream>, EventPublisher>(_eventPublisher); configuration.SetDefault<IPublisher<DomainEventStream>, EventPublisher>(_eventPublisher); configuration.SetDefault<IPublisher<IEvent>, EventPublisher>(_eventPublisher); _commandConsumer = new CommandConsumer(); _eventConsumer = new EventConsumer(); var commandTopics = ObjectContainer.Resolve<ITopicProvider<ICommand>>().GetAllTopics(); var eventTopics = ObjectContainer.Resolve<ITopicProvider<IEvent>>().GetAllTopics(); commandTopics.ForEach(topic => _commandConsumer.Subscribe(topic)); eventTopics.ForEach(topic => _eventConsumer.Subscribe(topic)); return enodeConfiguration; }
public Task CommandWithResult_FromAsyncHandler() { MockCommandResult result = null; return(CommandConsumer.Test( async c => { c.Build(); var domainEventSrv = c.Services.Resolve <IMessagingService>(); var evt = new MockCommand(); var futureResult = domainEventSrv.PublishAsync(evt); result = await futureResult; }, (IAppContainer c) => { result.Should().NotBeNull(); result.Value.Should().Be("MOCK_VALUE"); var consumer = c.Services.Resolve <MockCommandConsumer>(); consumer.ExecutedHandlers.Should().HaveCount(1); consumer.ExecutedHandlers.Should().Contain("OnCommand"); })); }
public static ENodeConfiguration UseEQueue(this ENodeConfiguration enodeConfiguration) { var configuration = enodeConfiguration.GetCommonConfiguration(); configuration.RegisterEQueueComponents(); _broker = BrokerController.Create(); _commandResultProcessor = new CommandResultProcessor(new IPEndPoint(SocketUtils.GetLocalIPV4(), 9000)); _commandService = new CommandService(_commandResultProcessor); _eventPublisher = new DomainEventPublisher(); configuration.SetDefault <ICommandService, CommandService>(_commandService); configuration.SetDefault <IMessagePublisher <DomainEventStreamMessage>, DomainEventPublisher>(_eventPublisher); _commandConsumer = new CommandConsumer(); _eventConsumer = new DomainEventConsumer(); _commandConsumer.Subscribe("NoteCommandTopic"); _eventConsumer.Subscribe("NoteEventTopic"); return(enodeConfiguration); }
public static ENodeConfiguration UseEQueue(this ENodeConfiguration enodeConfiguration) { var configuration = enodeConfiguration.GetCommonConfiguration(); configuration.RegisterEQueueComponents(); _broker = new BrokerController(); _commandResultProcessor = new CommandResultProcessor(); _commandService = new CommandService(_commandResultProcessor); _eventPublisher = new EventPublisher(); configuration.SetDefault<ICommandService, CommandService>(_commandService); configuration.SetDefault<IEventPublisher, EventPublisher>(_eventPublisher); _commandConsumer = new CommandConsumer(); _eventConsumer = new EventConsumer(); _commandConsumer.Subscribe("BankTransferCommandTopic"); _eventConsumer.Subscribe("BankTransferEventTopic"); return enodeConfiguration; }
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); }
public static ENodeConfiguration UseEQueue(this ENodeConfiguration enodeConfiguration) { var configuration = enodeConfiguration.GetCommonConfiguration(); var brokerStorePath = @"d:\equeue-store-test"; if (Directory.Exists(brokerStorePath)) { Directory.Delete(brokerStorePath, true); } configuration.RegisterEQueueComponents(); _broker = BrokerController.Create(new BrokerSetting(brokerStorePath)); _commandResultProcessor = new CommandResultProcessor(new IPEndPoint(SocketUtils.GetLocalIPV4(), 9000)); _commandService = new CommandService(_commandResultProcessor); _eventPublisher = new DomainEventPublisher(); configuration.SetDefault<ICommandService, CommandService>(_commandService); configuration.SetDefault<IMessagePublisher<DomainEventStreamMessage>, DomainEventPublisher>(_eventPublisher); _commandConsumer = new CommandConsumer(); _eventConsumer = new DomainEventConsumer(); _commandConsumer .Subscribe("AccountCommandTopic") .Subscribe("SectionCommandTopic") .Subscribe("PostCommandTopic") .Subscribe("ReplyCommandTopic"); _eventConsumer .Subscribe("AccountEventTopic") .Subscribe("SectionEventTopic") .Subscribe("PostEventTopic") .Subscribe("ReplyEventTopic"); return enodeConfiguration; }
public void Stop() { if (!IsRuning) { return; } try { // 控制器服务 if (commandCustomer != null) { commandCustomer.Stop(); if (!commandCustomer.IsRuning) { TraceManagerForWeb.AppendDebug("Scada-WEB-压力监测点控制器服务已停止"); this.commandCustomer = null; } else { TraceManagerForWeb.AppendErrMsg("Scada-WEB-压力监测点控制器服务停止失败"); } } } catch { } // 关闭定时器 if (timer != null) { timer.Enabled = false; timer.Close(); timer = null; } IsRuning = false; }
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(); } }
public static ENodeConfiguration UseEQueue(this ENodeConfiguration enodeConfiguration) { var configuration = enodeConfiguration.GetCommonConfiguration(); configuration.RegisterEQueueComponents(); _broker = new BrokerController(); _commandResultProcessor = new CommandResultProcessor(); _commandService = new CommandService(_commandResultProcessor); _eventPublisher = new DomainEventPublisher(); configuration.SetDefault<ICommandService, CommandService>(_commandService); configuration.SetDefault<IMessagePublisher<DomainEventStreamMessage>, DomainEventPublisher>(_eventPublisher); _commandConsumer = new CommandConsumer(); _eventConsumer = new DomainEventConsumer(); _commandConsumer .Subscribe("AccountCommandTopic") .Subscribe("SectionCommandTopic") .Subscribe("PostCommandTopic") .Subscribe("ReplyCommandTopic"); _eventConsumer .Subscribe("AccountEventTopic") .Subscribe("SectionEventTopic") .Subscribe("PostEventTopic") .Subscribe("ReplyEventTopic"); return enodeConfiguration; }
public static ENodeConfiguration UseEQueue(this ENodeConfiguration enodeConfiguration) { var configuration = enodeConfiguration.GetCommonConfiguration(); configuration.RegisterEQueueComponents(); var producerSetting = new ProducerSetting { BrokerProducerIPEndPoint = new IPEndPoint(SocketUtils.GetLocalIPV4(), ConfigSettings.BrokerProducerPort) }; var consumerSetting = new ConsumerSetting { BrokerConsumerIPEndPoint = new IPEndPoint(SocketUtils.GetLocalIPV4(), ConfigSettings.BrokerConsumerPort) }; _applicationMessagePublisher = new ApplicationMessagePublisher("ConferenceApplicationMessagePublisher", producerSetting); _domainEventPublisher = new DomainEventPublisher("ConferenceDomainEventPublisher", producerSetting); _exceptionPublisher = new PublishableExceptionPublisher("ConferencePublishableExceptionPublisher", producerSetting); configuration.SetDefault<IMessagePublisher<IApplicationMessage>, ApplicationMessagePublisher>(_applicationMessagePublisher); configuration.SetDefault<IMessagePublisher<DomainEventStreamMessage>, DomainEventPublisher>(_domainEventPublisher); configuration.SetDefault<IMessagePublisher<IPublishableException>, PublishableExceptionPublisher>(_exceptionPublisher); _commandConsumer = new CommandConsumer( "ConferenceCommandConsumer", "ConferenceCommandConsumerGroup", consumerSetting) .Subscribe(Topics.ConferenceCommandTopic); _eventConsumer = new DomainEventConsumer( "ConferenceEventConsumer", "ConferenceEventConsumerGroup", consumerSetting) .Subscribe(Topics.ConferenceDomainEventTopic); _exceptionConsumer = new PublishableExceptionConsumer( "ConferenceExceptionConsumer", "ConferenceExceptionConsumerGroup", consumerSetting) .Subscribe(Topics.ConferenceExceptionTopic); return enodeConfiguration; }
public static ENodeConfiguration UseEQueue(this ENodeConfiguration enodeConfiguration) { var configuration = enodeConfiguration.GetCommonConfiguration(); configuration.RegisterEQueueComponents(); configuration.SetDefault<ICommandTopicProvider, CommandTopicManager>(); configuration.SetDefault<IEventTopicProvider, EventTopicManager>(); configuration.SetDefault<ICommandTypeCodeProvider, CommandTypeCodeManager>(); var consumerSetting = new ConsumerSetting { HeartbeatBrokerInterval = 1000, UpdateTopicQueueCountInterval = 1000, RebalanceInterval = 1000 }; var eventConsumerSetting = new ConsumerSetting { HeartbeatBrokerInterval = 1000, UpdateTopicQueueCountInterval = 1000, RebalanceInterval = 1000, MessageHandleMode = MessageHandleMode.Sequential }; _broker = new BrokerController().Initialize(); var commandExecutedMessageConsumer = new Consumer(consumerSetting, "CommandExecutedMessageConsumer", "CommandExecutedMessageConsumerGroup_" + ObjectId.GenerateNewId().ToString()); var domainEventHandledMessageConsumer = new Consumer(consumerSetting, "DomainEventHandledMessageConsumer", "DomainEventHandledMessageConsumerGroup_" + ObjectId.GenerateNewId().ToString()); _commandResultProcessor = new CommandResultProcessor(commandExecutedMessageConsumer, domainEventHandledMessageConsumer); _commandService = new CommandService(_commandResultProcessor); _commandExecutedMessageSender = new CommandExecutedMessageSender(); _domainEventHandledMessageSender = new DomainEventHandledMessageSender(); _eventPublisher = new EventPublisher(); configuration.SetDefault<ICommandService, CommandService>(_commandService); configuration.SetDefault<IEventPublisher, EventPublisher>(_eventPublisher); _commandConsumer = new CommandConsumer(consumerSetting, _commandExecutedMessageSender); _eventConsumer = new EventConsumer(eventConsumerSetting, _domainEventHandledMessageSender); _commandConsumer.Subscribe("NoteCommandTopic"); _eventConsumer.Subscribe("NoteEventTopic"); _commandResultProcessor.SetExecutedCommandMessageTopic("ExecutedCommandMessageTopic"); _commandResultProcessor.SetDomainEventHandledMessageTopic("DomainEventHandledMessageTopic"); return enodeConfiguration; }
static void Main2(string[] args) { var environment = new List<KeyValuePair<string, string>>(); environment.Add(new KeyValuePair<string, string>("MongoServer", "localhost")); environment.Add(new KeyValuePair<string, string>("MongoPort", "27017")); environment.Add(new KeyValuePair<string, string>("MongoRepositorySvcConfig", "ServiceConfig")); environment.Add(new KeyValuePair<string, string>("RabbitMQServer", "localhost")); environment.Add(new KeyValuePair<string, string>("RabbitMQPort", "5672")); environment.Add(new KeyValuePair<string, string>("RabbitMQVHost", "/Dev")); var mongoEnv = environment.Where(kvp => kvp.Key.StartsWith("Mongo")); var rabbitEnv = environment.Where(kvp => kvp.Key.StartsWith("Rabbit")); using (var mbc = new MessageBrokerConnection(rabbitEnv)) { using (var cl = new CommandConsumer(mbc.Connection)) { cl.RegisterCommandHandler<ReloadFiles>((props, cmd) => { //Console.WriteLine("{0:G}: {1}", cmd.Created.ToLocalTime(), props.Type); return new ReloadFilesAck(cmd); }); var loops = 10000; var successCounter = 0; var failCounter = 0; var cumulativeTime = 0L; var sw = new Stopwatch(); var cmdExchange = Constants.CmdExchangeSettings; using (var cs = new CommandProducer(mbc.Connection)) { for (int i = 0; i < loops; i++) { sw.Reset(); sw.Start(); var reply = cs.Publish(new ReloadFiles(), cl.PublicationAddress, TimeSpan.FromMilliseconds(20d)); sw.Stop(); if (reply != null) { ++successCounter; cumulativeTime += sw.ElapsedMilliseconds; } else ++failCounter; } } Console.WriteLine("{0} Command(s) Sent, {1} Successes, {2} Fails, {3}ms elapsed", loops, successCounter, failCounter, cumulativeTime); Console.WriteLine("Press Enter to continue"); Console.ReadLine(); } } }