Esempio n. 1
0
        public static ENodeConfiguration UseEQueue(this ENodeConfiguration enodeConfiguration)
        {
            var configuration = enodeConfiguration.GetCommonConfiguration();

            configuration.RegisterEQueueComponents();

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

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

            _commandService = new CommandService(null, producerSetting);
            configuration.SetDefault <ICommandService, CommandService>(_commandService);

            _commandConsumer = new CommandConsumer("ShopCommandConsumerGroup", consumerSetting).Subscribe(Topics.ShopCommandTopic);
            _eventConsumer   = new DomainEventConsumer("ShopEventConsumerGroup", consumerSetting).Subscribe(Topics.ShopDomainEventTopic);

            _applicationMessageConsumer = new ApplicationMessageConsumer("ShopMessageConsumerGroup", consumerSetting)
                                          .Subscribe(Topics.ShopApplicationMessageTopic);
            //.Subscribe(Topics.PaymentApplicationMessageTopic);

            _applicationMessagePublisher = new ApplicationMessagePublisher(producerSetting);

            _exceptionPublisher = new PublishableExceptionPublisher(producerSetting);


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

            _exceptionConsumer = new PublishableExceptionConsumer("ShopExceptionConsumerGroup", consumerSetting).Subscribe(Topics.ShopExceptionTopic);

            return(enodeConfiguration);
        }
Esempio n. 2
0
        public static ENodeConfiguration StartKafka(this ENodeConfiguration enodeConfiguration)
        {
            var kafkaConfig = ObjectContainer.Resolve <Jane.ENode.IKafkaConfiguration>();

            var producerSetting = new ProducerSetting
            {
                BrokerEndPoints = kafkaConfig.BrokerEndPoints
            };

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

            _commandResultProcessor.Start();
            _commandService.Start();

            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();

            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);
        }
Esempio n. 5
0
        static void SendMessages()
        {
            var setting = new ProducerSetting
            {
                BrokerAddress      = new IPEndPoint(SocketUtils.GetLocalIPV4(), 5000),
                BrokerAdminAddress = new IPEndPoint(SocketUtils.GetLocalIPV4(), 5002)
            };
            var producer = new Producer(setting).Start();
            var index    = 0L;

            while (true)
            {
                var payload = Encoding.UTF8.GetBytes(index.ToString());
                var message = new Message("topic1", 100, payload);

                SendMessageAsync(producer, message, index.ToString());

                index++;
                Thread.Sleep(10);
            }
        }
Esempio n. 6
0
        static void SendMessageTest()
        {
            var clusterName       = ConfigurationManager.AppSettings["ClusterName"];
            var address           = ConfigurationManager.AppSettings["NameServerAddress"];
            var nameServerAddress = string.IsNullOrEmpty(address) ? SocketUtils.GetLocalIPV4() : IPAddress.Parse(address);
            var clientCount       = int.Parse(ConfigurationManager.AppSettings["ClientCount"]);
            var messageSize       = int.Parse(ConfigurationManager.AppSettings["MessageSize"]);
            var messageCount      = long.Parse(ConfigurationManager.AppSettings["MessageCount"]);
            var batchSize         = int.Parse(ConfigurationManager.AppSettings["BatchSize"]);
            var actions           = new List <Action>();
            var payload           = new byte[messageSize];
            var topic             = ConfigurationManager.AppSettings["Topic"];

            for (var i = 0; i < clientCount; i++)
            {
                var setting = new ProducerSetting
                {
                    ClusterName    = clusterName,
                    NameServerList = new List <IPEndPoint> {
                        new IPEndPoint(nameServerAddress, 9493)
                    }
                };

                var producer = new Producer(setting);

                if (_mode == "Callback")
                {
                    producer.RegisterResponseHandler(new ResponseHandler {
                        BatchSize = batchSize
                    });
                }
                producer.Start();

                actions.Add(() => SendMessages(producer, _mode, batchSize, messageCount, topic, payload));
            }

            //模拟并发
            Task.Factory.StartNew(() => Parallel.Invoke(actions.ToArray()));
        }
Esempio n. 7
0
        public static ENodeConfiguration UseEQueue(this ENodeConfiguration enodeConfiguration)
        {
            var configuration = enodeConfiguration.GetCommonConfiguration();

            configuration.RegisterEQueueComponents();
            var nameServerEndpoint  = new IPEndPoint(SocketUtils.GetLocalIPV4(), 10000);
            var nameServerEndpoints = new List <IPEndPoint> {
                nameServerEndpoint
            };
            var nameServerSetting = new NameServerSetting()
            {
                BindingAddress = nameServerEndpoint
            };

            var producerSetting = new ProducerSetting
            {
                NameServerList = nameServerEndpoints
            };

            _commandService = new CommandService(null, producerSetting);
            configuration.SetDefault <ICommandService, CommandService>(_commandService);
            return(enodeConfiguration);
        }
Esempio n. 8
0
        public static ENodeConfiguration UseEQueue(this ENodeConfiguration enodeConfiguration)
        {
            var configuration = enodeConfiguration.GetCommonConfiguration();

            configuration.RegisterEQueueComponents();

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

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

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

            _commandConsumer = new CommandConsumer("GPermissionCommandConsumerGroup", consumerSetting).Subscribe(
                Topics.GPermissionCommandTopic);
            _eventConsumer = new DomainEventConsumer("GPermissionEventConsumerGroup", consumerSetting).Subscribe(
                Topics.GPermissionDomainEventTopic);
            _exceptionConsumer = new PublishableExceptionConsumer("GPermissionExceptionConsumerGroup", consumerSetting)
                                 .Subscribe(Topics.GPermissionExceptionTopic);
            return(enodeConfiguration);
        }
Esempio n. 9
0
 public CommandService Initialize(CommandResultProcessor commandResultProcessor = null, ProducerSetting setting = null)
 {
     _commandResultProcessor = commandResultProcessor;
     _producer                = new Producer(setting);
     _jsonSerializer          = ObjectContainer.Resolve <IJsonSerializer>();
     _commandTopicProvider    = ObjectContainer.Resolve <ITopicProvider <ICommand> >();
     _typeNameProvider        = ObjectContainer.Resolve <ITypeNameProvider>();
     _commandRouteKeyProvider = ObjectContainer.Resolve <ICommandRoutingKeyProvider>();
     _sendMessageService      = new SendQueueMessageService();
     _logger   = ObjectContainer.Resolve <ILoggerFactory>().Create(GetType().FullName);
     _ioHelper = ObjectContainer.Resolve <IOHelper>();
     return(this);
 }
Esempio n. 10
0
 public ApplicationMessagePublisher InitializeKafka(ProducerSetting producerSetting, Dictionary <string, object> kafkaConfig = null)
 {
     InitializeENode();
     Producer = new Producer(producerSetting);
     return(this);
 }
 public DomainEventPublisher InitializeKafka(ProducerSetting producerSetting)
 {
     InitializeENode();
     Producer = new Producer(producerSetting);
     return(this);
 }
Esempio n. 12
0
 public CommandService InitializeEQueue(CommandResultProcessor commandResultProcessor = null, ProducerSetting setting = null)
 {
     InitializeENode();
     _commandResultProcessor = commandResultProcessor;
     Producer = new Producer(setting, "CommandService");
     return(this);
 }
Esempio n. 13
0
        public static ENodeConfiguration StartEQueue(this ENodeConfiguration enodeConfiguration)
        {
            if (_isEQueueStarted)
            {
                _commandService.InitializeENode();
                _eventPublisher.InitializeENode();
                _applicationMessagePublisher.InitializeENode();
                _domainExceptionPublisher.InitializeENode();

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

                return(enodeConfiguration);
            }

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

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

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

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

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

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

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

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

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

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

            _isEQueueStarted = true;

            return(enodeConfiguration);
        }
 public PublishableExceptionPublisher InitializeKafka(ProducerSetting producerSetting)
 {
     InitializeENode();
     Producer = new Producer(producerSetting);
     return(this);
 }
Esempio n. 15
0
 public CommandService(CommandResultProcessor commandResultProcessor = null, string id = null, ProducerSetting setting = null)
 {
     _commandResultProcessor = commandResultProcessor;
     _producer                = new Producer(id ?? DefaultCommandServiceProcuderId, setting ?? new ProducerSetting());
     _jsonSerializer          = ObjectContainer.Resolve <IJsonSerializer>();
     _commandTopicProvider    = ObjectContainer.Resolve <ITopicProvider <ICommand> >();
     _commandTypeCodeProvider = ObjectContainer.Resolve <ITypeCodeProvider>();
     _commandRouteKeyProvider = ObjectContainer.Resolve <ICommandRoutingKeyProvider>();
     _sendMessageService      = new SendQueueMessageService();
     _logger   = ObjectContainer.Resolve <ILoggerFactory>().Create(GetType().FullName);
     _ioHelper = ObjectContainer.Resolve <IOHelper>();
     CommandExecutedMessageTopic    = DefaultCommandExecutedMessageTopic;
     DomainEventHandledMessageTopic = DefaultDomainEventHandledMessageTopic;
 }
Esempio n. 16
0
 public ApplicationMessagePublisher InitializeEQueue(ProducerSetting setting = null)
 {
     InitializeENode();
     Producer = new Producer(setting, "ApplicationMessagePublisher");
     return(this);
 }
 public PublishableExceptionPublisher InitializeEQueue(ProducerSetting setting = null)
 {
     InitializeENode();
     Producer = new Producer(setting, "PublishableExceptionPublisher");
     return(this);
 }
        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);
        }
Esempio n. 19
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();
            }
        }
Esempio n. 20
0
        public static ENodeConfiguration StartKafka(this ENodeConfiguration enodeConfiguration)
        {
            var kafkaConfig = ObjectContainer.Resolve <Jane.ENode.IKafkaConfiguration>();

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

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

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

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

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

            return(enodeConfiguration);
        }
 public DomainEventHandledMessageSender(string id = null, ProducerSetting setting = null)
 {
     _producer       = new Producer(id ?? DefaultDomainEventHandledMessageSenderProcuderId, setting ?? new ProducerSetting());
     _jsonSerializer = ObjectContainer.Resolve <IJsonSerializer>();
     _ioHelper       = ObjectContainer.Resolve <IOHelper>();
 }
Esempio n. 22
0
 public DomainEventPublisher InitializeEQueue(ProducerSetting setting = null)
 {
     InitializeENode();
     Producer = new Producer(setting, "DomainEventPublisher");
     return(this);
 }
Esempio n. 23
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();
            }
        }