Exemple #1
0
        public Consumer(string groupName, ConsumerSetting setting)
        {
            if (groupName == null)
            {
                throw new ArgumentNullException("groupName");
            }
            GroupName = groupName;
            Setting   = setting ?? new ConsumerSetting();

            _lockObject                   = new object();
            _subscriptionTopics           = new Dictionary <string, HashSet <string> >();
            _topicQueuesDict              = new ConcurrentDictionary <string, IList <MessageQueue> >();
            _pullRequestDict              = new ConcurrentDictionary <string, PullRequest>();
            _remotingClient               = new SocketRemotingClient(Setting.BrokerAddress, Setting.SocketSetting, Setting.LocalAddress);
            _adminRemotingClient          = new SocketRemotingClient(Setting.BrokerAdminAddress, Setting.SocketSetting, Setting.LocalAdminAddress);
            _binarySerializer             = ObjectContainer.Resolve <IBinarySerializer>();
            _scheduleService              = ObjectContainer.Resolve <IScheduleService>();
            _allocateMessageQueueStragegy = ObjectContainer.Resolve <IAllocateMessageQueueStrategy>();
            _logger = ObjectContainer.Resolve <ILoggerFactory>().Create(GetType().FullName);

            _adminRemotingClient.RegisterConnectionEventListener(new ConnectionEventListener(this));

            if (Setting.MessageHandleMode == MessageHandleMode.Sequential)
            {
                _consumingMessageQueue = new BlockingCollection <ConsumingMessage>();
                _consumeMessageWorker  = new Worker("ConsumeMessage", () => HandleMessage(_consumingMessageQueue.Take()));
            }
            _messageRetryQueue = new BlockingCollection <ConsumingMessage>();
        }
Exemple #2
0
        static void InitializeEQueue()
        {
            ECommonConfiguration
                .Create()
                .UseAutofac()
                .RegisterCommonComponents()
                .UseLog4Net()
                .UseJsonNet()
                .RegisterUnhandledExceptionHandler()
                .RegisterEQueueComponents();

            var clientCount = int.Parse(ConfigurationManager.AppSettings["ClientCount"]);
            var consumerSetting = new ConsumerSetting
            {
                ConsumeFromWhere = ConsumeFromWhere.FirstOffset
            };
            var messageHandler = new MessageHandler();
            for (var i = 1; i <= clientCount; i++)
            {
                new Consumer(ConfigurationManager.AppSettings["ConsumerGroup"], consumerSetting)
                    .Subscribe(ConfigurationManager.AppSettings["Topic"])
                    .SetMessageHandler(messageHandler)
                    .Start();
            }
        }
Exemple #3
0
        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;
        }
Exemple #4
0
        public Consumer(string groupName, ConsumerSetting setting, string consumerName = null)
        {
            if (groupName == null)
            {
                throw new ArgumentNullException("groupName");
            }

            Name = consumerName;
            GroupName = groupName;
            Setting = setting ?? new ConsumerSetting();

            if (Setting.NameServerList == null || Setting.NameServerList.Count() == 0)
            {
                throw new Exception("Name server address is not specified.");
            }

            _subscriptionTopics = new Dictionary<string, HashSet<string>>();
            _binarySerializer = ObjectContainer.Resolve<IBinarySerializer>();
            _logger = ObjectContainer.Resolve<ILoggerFactory>().Create(GetType().FullName);

            var clientSetting = new ClientSetting
            {
                ClientName = Name,
                ClusterName = Setting.ClusterName,
                NameServerList = Setting.NameServerList,
                SocketSetting = Setting.SocketSetting,
                OnlyFindMasterBroker = true,
                SendHeartbeatInterval = Setting.HeartbeatBrokerInterval,
                RefreshBrokerAndTopicRouteInfoInterval = Setting.RefreshBrokerAndTopicRouteInfoInterval
            };
            _clientService = new ClientService(clientSetting, null, this);
            _pullMessageService = new PullMessageService(this, _clientService);
            _commitConsumeOffsetService = new CommitConsumeOffsetService(this, _clientService);
            _rebalanceService = new RebalanceService(this, _clientService, _pullMessageService, _commitConsumeOffsetService);
        }
Exemple #5
0
        public Consumer(string id, string groupName, ConsumerSetting setting)
        {
            if (id == null)
            {
                throw new ArgumentNullException("id");
            }
            if (groupName == null)
            {
                throw new ArgumentNullException("groupName");
            }
            Id        = id;
            GroupName = groupName;
            Setting   = setting ?? new ConsumerSetting();

            _lockObject            = new object();
            _subscriptionTopics    = new ConcurrentBag <string>();
            _topicQueuesDict       = new ConcurrentDictionary <string, IList <MessageQueue> >();
            _consumingMessageQueue = new BlockingCollection <ConsumingMessage>(new ConcurrentQueue <ConsumingMessage>());
            _messageRetryQueue     = new BlockingCollection <ConsumingMessage>(new ConcurrentQueue <ConsumingMessage>());
            _handlingMessageDict   = new ConcurrentDictionary <string, ConsumingMessage>();
            _finishedMessageTag    = new ConcurrentQueue <ulong>();
            _taskIds     = new List <int>();
            _taskFactory = new TaskFactory(new LimitedConcurrencyLevelTaskScheduler(Setting.ConsumeThreadMaxCount));


            _binarySerializer = ObjectContainer.Resolve <IBinarySerializer>();
            _scheduleService  = ObjectContainer.Resolve <IScheduleService>();
            //_allocateMessageQueueStragegy = PF.Global.Interfaces.IOCContainer.Resolve<IAllocateMessageQueueStrategy>();
            _logger = ObjectContainer.Resolve <ILoggerFactory>().Create(GetType().FullName);
            //_waitSocketConnectHandle = new AutoResetEvent(false);
        }
Exemple #6
0
        public Consumer(string id, string groupName, ConsumerSetting setting)
        {
            if (id == null)
            {
                throw new ArgumentNullException("id");
            }
            if (groupName == null)
            {
                throw new ArgumentNullException("groupName");
            }
            Id        = id;
            GroupName = groupName;
            Setting   = setting ?? new ConsumerSetting();

            _lockObject            = new object();
            _subscriptionTopics    = new List <string>();
            _topicQueuesDict       = new ConcurrentDictionary <string, IList <MessageQueue> >();
            _pullRequestQueue      = new BlockingCollection <PullRequest>(new ConcurrentQueue <PullRequest>());
            _pullRequestDict       = new ConcurrentDictionary <string, PullRequest>();
            _consumingMessageQueue = new BlockingCollection <ConsumingMessage>(new ConcurrentQueue <ConsumingMessage>());
            _messageRetryQueue     = new BlockingCollection <ConsumingMessage>(new ConcurrentQueue <ConsumingMessage>());
            _handlingMessageDict   = new ConcurrentDictionary <long, ConsumingMessage>();
            _taskIds                      = new List <int>();
            _taskFactory                  = new TaskFactory(new LimitedConcurrencyLevelTaskScheduler(Setting.ConsumeThreadMaxCount));
            _remotingClient               = new SocketRemotingClient(Setting.BrokerConsumerIPEndPoint, null, this);
            _binarySerializer             = ObjectContainer.Resolve <IBinarySerializer>();
            _scheduleService              = ObjectContainer.Resolve <IScheduleService>();
            _allocateMessageQueueStragegy = ObjectContainer.Resolve <IAllocateMessageQueueStrategy>();
            _executePullRequestWorker     = new Worker("Consumer.ExecutePullRequest", ExecutePullRequest);
            _handleMessageWorker          = new Worker("Consumer.HandleMessage", HandleMessage);
            _logger = ObjectContainer.Resolve <ILoggerFactory>().Create(GetType().FullName);
            _waitSocketConnectHandle = new AutoResetEvent(false);
        }
Exemple #7
0
        public Consumer(string groupName, ConsumerSetting setting)
        {
            if (groupName == null)
            {
                throw new ArgumentNullException("groupName");
            }
            GroupName = groupName;
            Setting = setting ?? new ConsumerSetting();

            _lockObject = new object();
            _subscriptionTopics = new Dictionary<string, HashSet<string>>();
            _topicQueuesDict = new ConcurrentDictionary<string, IList<MessageQueue>>();
            _pullRequestDict = new ConcurrentDictionary<string, PullRequest>();
            _remotingClient = new SocketRemotingClient(Setting.BrokerAddress, Setting.SocketSetting, Setting.LocalAddress);
            _adminRemotingClient = new SocketRemotingClient(Setting.BrokerAdminAddress, Setting.SocketSetting, Setting.LocalAdminAddress);
            _binarySerializer = ObjectContainer.Resolve<IBinarySerializer>();
            _scheduleService = ObjectContainer.Resolve<IScheduleService>();
            _allocateMessageQueueStragegy = ObjectContainer.Resolve<IAllocateMessageQueueStrategy>();
            _logger = ObjectContainer.Resolve<ILoggerFactory>().Create(GetType().FullName);

            _remotingClient.RegisterConnectionEventListener(new ConnectionEventListener(this));

            if (Setting.MessageHandleMode == MessageHandleMode.Sequential)
            {
                _consumingMessageQueue = new BlockingCollection<ConsumingMessage>();
                _consumeMessageWorker = new Worker("ConsumeMessage", () => HandleMessage(_consumingMessageQueue.Take()));
            }
            _messageRetryQueue = new BlockingCollection<ConsumingMessage>();
        }
Exemple #8
0
        static void InitializeEQueue()
        {
            ECommonConfiguration
                .Create()
                .UseAutofac()
                .RegisterCommonComponents()
                .UseLog4Net()
                .UseJsonNet()
                .RegisterUnhandledExceptionHandler()
                .RegisterEQueueComponents();
            _logger = ObjectContainer.Resolve<ILoggerFactory>().Create("Program");

            var clientCount = int.Parse(ConfigurationManager.AppSettings["ClientCount"]);
            var consumerSetting = new ConsumerSetting
            {
                HeartbeatBrokerInterval = 1000,
                UpdateTopicQueueCountInterval = 1000,
                RebalanceInterval = 1000,
                ConsumeFromWhere = ConsumeFromWhere.FirstOffset
            };
            var messageHandler = new MessageHandler();
            for (var i = 1; i <= clientCount; i++)
            {
                new Consumer("Consumer@" + i.ToString(), "SampleGroup", consumerSetting)
                    .Subscribe("SampleTopic")
                    .SetMessageHandler(messageHandler)
                    .Start();
            }
        }
Exemple #9
0
        static void Main(string[] args)
        {
            InitializeEQueue();

            var messageHandler = new MessageHandler();
            var consumerSetting = new ConsumerSetting { HeartbeatBrokerInterval = 1000, UpdateTopicQueueCountInterval = 1000, RebalanceInterval = 1000 };
            var consumer1 = new Consumer("Consumer1", "group1", consumerSetting).Subscribe("SampleTopic").Start(messageHandler);
            var consumer2 = new Consumer("Consumer2", "group1", consumerSetting).Subscribe("SampleTopic").Start(messageHandler);

            _logger.Info("Start consumer load balance, please wait for a moment.");
            var scheduleService = ObjectContainer.Resolve<IScheduleService>();
            var waitHandle = new ManualResetEvent(false);
            var taskId = scheduleService.ScheduleTask(() =>
            {
                var c1AllocatedQueueIds = consumer1.GetCurrentQueues().Select(x => x.QueueId);
                var c2AllocatedQueueIds = consumer2.GetCurrentQueues().Select(x => x.QueueId);
                if (c1AllocatedQueueIds.Count() == 2 && c2AllocatedQueueIds.Count() == 2)
                {
                    _logger.Info(string.Format("Consumer load balance finished. Queue allocation result: c1:{0}, c2:{1}",
                        string.Join(",", c1AllocatedQueueIds),
                        string.Join(",", c2AllocatedQueueIds)));
                    waitHandle.Set();
                }
            }, 1000, 1000);

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

            Console.ReadLine();
        }
Exemple #10
0
        public Consumer(string groupName, ConsumerSetting setting)
        {
            if (groupName == null)
            {
                throw new ArgumentNullException("groupName");
            }
            GroupName = groupName;
            Setting = setting ?? new ConsumerSetting();

            _lockObject = new object();
            _subscriptionTopics = new Dictionary<string, HashSet<string>>();
            _topicQueuesDict = new ConcurrentDictionary<string, IList<MessageQueue>>();
            _pullRequestQueue = new BlockingCollection<PullRequest>(new ConcurrentQueue<PullRequest>());
            _pullRequestDict = new ConcurrentDictionary<string, PullRequest>();
            _messageRetryQueue = new BlockingCollection<ConsumingMessage>(new ConcurrentQueue<ConsumingMessage>());
            _taskFactory = new TaskFactory(new LimitedConcurrencyLevelTaskScheduler(Setting.ConsumeThreadMaxCount));
            _remotingClient = new SocketRemotingClient(Setting.BrokerAddress, Setting.SocketSetting, Setting.LocalAddress);
            _adminRemotingClient = new SocketRemotingClient(Setting.BrokerAdminAddress, Setting.SocketSetting, Setting.LocalAdminAddress);
            _binarySerializer = ObjectContainer.Resolve<IBinarySerializer>();
            _scheduleService = ObjectContainer.Resolve<IScheduleService>();
            _allocateMessageQueueStragegy = ObjectContainer.Resolve<IAllocateMessageQueueStrategy>();
            _executePullRequestWorker = new Worker("ExecutePullRequest", ExecutePullRequest);
            _logger = ObjectContainer.Resolve<ILoggerFactory>().Create(GetType().FullName);

            _remotingClient.RegisterConnectionEventListener(new ConnectionEventListener(this));
        }
        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;
        }
Exemple #12
0
        static void InitializeEQueue()
        {
            ECommonConfiguration
                .Create()
                .UseAutofac()
                .RegisterCommonComponents()
                .UseLog4Net()
                .UseJsonNet()
                .RegisterUnhandledExceptionHandler()
                .RegisterEQueueComponents();

            var address = ConfigurationManager.AppSettings["BrokerAddress"];
            var brokerAddress = string.IsNullOrEmpty(address) ? SocketUtils.GetLocalIPV4() : IPAddress.Parse(address);
            var clientCount = int.Parse(ConfigurationManager.AppSettings["ClientCount"]);
            var setting = new ConsumerSetting
            {
                ConsumeFromWhere = ConsumeFromWhere.FirstOffset,
                MessageHandleMode = MessageHandleMode.Parallel,
                BrokerAddress = new IPEndPoint(brokerAddress, 5001),
                BrokerAdminAddress = new IPEndPoint(brokerAddress, 5002)
            };
            var messageHandler = new MessageHandler();
            for (var i = 1; i <= clientCount; i++)
            {
                new Consumer(ConfigurationManager.AppSettings["ConsumerGroup"], setting)
                    .Subscribe(ConfigurationManager.AppSettings["Topic"])
                    .SetMessageHandler(messageHandler)
                    .Start();
            }
        }
Exemple #13
0
        public Consumer(string id, string groupName, ConsumerSetting setting)
        {
            if (id == null)
            {
                throw new ArgumentNullException("id");
            }
            if (groupName == null)
            {
                throw new ArgumentNullException("groupName");
            }
            Id = id;
            GroupName = groupName;
            Setting = setting ?? new ConsumerSetting();

            _lockObject = new object();
            _subscriptionTopics = new List<string>();
            _topicQueuesDict = new ConcurrentDictionary<string, IList<MessageQueue>>();
            _pullRequestQueue = new BlockingCollection<PullRequest>(new ConcurrentQueue<PullRequest>());
            _pullRequestDict = new ConcurrentDictionary<string, PullRequest>();
            _consumingMessageQueue = new BlockingCollection<ConsumingMessage>(new ConcurrentQueue<ConsumingMessage>());
            _messageRetryQueue = new BlockingCollection<ConsumingMessage>(new ConcurrentQueue<ConsumingMessage>());
            _handlingMessageDict = new ConcurrentDictionary<long, ConsumingMessage>();
            _taskIds = new List<int>();
            _taskFactory = new TaskFactory(new LimitedConcurrencyLevelTaskScheduler(Setting.ConsumeThreadMaxCount));
            _remotingClient = new SocketRemotingClient(Setting.BrokerConsumerIPEndPoint, null, this);
            _binarySerializer = ObjectContainer.Resolve<IBinarySerializer>();
            _scheduleService = ObjectContainer.Resolve<IScheduleService>();
            _allocateMessageQueueStragegy = ObjectContainer.Resolve<IAllocateMessageQueueStrategy>();
            _executePullRequestWorker = new Worker("Consumer.ExecutePullRequest", ExecutePullRequest);
            _handleMessageWorker = new Worker("Consumer.HandleMessage", HandleMessage);
            _logger = ObjectContainer.Resolve<ILoggerFactory>().Create(GetType().FullName);
            _waitSocketConnectHandle = new AutoResetEvent(false);
        }
Exemple #14
0
        static void Main(string[] args)
        {
            InitializeEQueue();

            var messageHandler = new MessageHandler();
            var consumerSetting = new ConsumerSetting
            {
                HeartbeatBrokerInterval = 1000,
                UpdateTopicQueueCountInterval = 1000,
                RebalanceInterval = 1000
            };
            var consumer = new Consumer("Consumer1", "Group1", consumerSetting).Subscribe("SampleTopic").SetMessageHandler(messageHandler).Start();

            _logger.Info("Start consumer load balance, please wait for a moment.");
            var scheduleService = ObjectContainer.Resolve<IScheduleService>();
            var waitHandle = new ManualResetEvent(false);
            var taskId = scheduleService.ScheduleTask("WaitQueueAllocationComplete", () =>
            {
                var allocatedQueueIds = consumer.GetCurrentQueues().Select(x => x.QueueId);
                if (allocatedQueueIds.Count() == 4)
                {
                    _logger.InfoFormat("Consumer load balance completed, allocated queueIds:{0}", string.Join(",", allocatedQueueIds));
                    waitHandle.Set();
                }
            }, 1000, 1000);

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

            Console.ReadLine();
        }
Exemple #15
0
        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;
        }
Exemple #16
0
        public static ENodeConfiguration UseEQueue(this ENodeConfiguration enodeConfiguration)
        {
            var configuration = enodeConfiguration.GetCommonConfiguration();

            configuration.RegisterEQueueComponents();

            var consumerSetting = new ConsumerSetting
            {
                HeartbeatBrokerInterval = 1000,
                UpdateTopicQueueCountInterval = 1000,
                RebalanceInterval = 1000
            };

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

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

            _commandResultProcessor.SetExecutedCommandMessageTopic("ExecutedCommandMessageTopic");
            _commandResultProcessor.SetDomainEventHandledMessageTopic("DomainEventHandledMessageTopic");

            return enodeConfiguration;
        }
Exemple #17
0
        public Consumer(string groupName, ConsumerSetting setting)
        {
            if (groupName == null)
            {
                throw new ArgumentNullException("groupName");
            }
            GroupName = groupName;
            Setting   = setting ?? new ConsumerSetting();

            _lockObject                   = new object();
            _subscriptionTopics           = new List <string>();
            _topicQueuesDict              = new ConcurrentDictionary <string, IList <MessageQueue> >();
            _pullRequestQueue             = new BlockingCollection <PullRequest>(new ConcurrentQueue <PullRequest>());
            _pullRequestDict              = new ConcurrentDictionary <string, PullRequest>();
            _messageRetryQueue            = new BlockingCollection <ConsumingMessage>(new ConcurrentQueue <ConsumingMessage>());
            _taskFactory                  = new TaskFactory(new LimitedConcurrencyLevelTaskScheduler(Setting.ConsumeThreadMaxCount));
            _remotingClient               = new SocketRemotingClient(Setting.BrokerAddress, Setting.SocketSetting, Setting.LocalAddress);
            _adminRemotingClient          = new SocketRemotingClient(Setting.BrokerAdminAddress, Setting.SocketSetting, Setting.LocalAdminAddress);
            _binarySerializer             = ObjectContainer.Resolve <IBinarySerializer>();
            _scheduleService              = ObjectContainer.Resolve <IScheduleService>();
            _allocateMessageQueueStragegy = ObjectContainer.Resolve <IAllocateMessageQueueStrategy>();
            _executePullRequestWorker     = new Worker("ExecutePullRequest", ExecutePullRequest);
            _logger = ObjectContainer.Resolve <ILoggerFactory>().Create(GetType().FullName);

            _remotingClient.RegisterConnectionEventListener(new ConnectionEventListener(this));
        }
 public DomainEventSubscriber(string name, EQueueClientsConsumers.ConsumerSetting consumerSetting,
                              string groupName, string subscribeTopic,
                              IHandlerProvider handlerProvider)
     : base(groupName, consumerSetting, groupName, subscribeTopic)
 {
     HandlerProvider = handlerProvider;
 }
Exemple #19
0
        static void StartConsumers()
        {
            var messageHandler = new MessageHandler();

            //Start four consumers.
            var consumerSetting = new ConsumerSetting { HeartbeatBrokerInterval = 1000, UpdateTopicQueueCountInterval = 1000, RebalanceInterval = 1000 };
            var consumer1 = new Consumer("Consumer1", "group1", consumerSetting).Subscribe("SampleTopic").SetMessageHandler(messageHandler).Start();
            var consumer2 = new Consumer("Consumer2", "group1", consumerSetting).Subscribe("SampleTopic").SetMessageHandler(messageHandler).Start();
            var consumer3 = new Consumer("Consumer3", "group1", consumerSetting).Subscribe("SampleTopic").SetMessageHandler(messageHandler).Start();
            var consumer4 = new Consumer("Consumer4", "group1", consumerSetting).Subscribe("SampleTopic").SetMessageHandler(messageHandler).Start();

            //Below to wait for consumer balance.
            _logger.Info("Start consumer load balance, please wait for a moment.");
            var scheduleService = ObjectContainer.Resolve<IScheduleService>();
            var waitHandle = new ManualResetEvent(false);
            var taskId = scheduleService.ScheduleTask("WaitQueueAllocationComplete", () =>
            {
                var c1AllocatedQueueIds = consumer1.GetCurrentQueues().Select(x => x.QueueId);
                var c2AllocatedQueueIds = consumer2.GetCurrentQueues().Select(x => x.QueueId);
                var c3AllocatedQueueIds = consumer3.GetCurrentQueues().Select(x => x.QueueId);
                var c4AllocatedQueueIds = consumer4.GetCurrentQueues().Select(x => x.QueueId);
                if (c1AllocatedQueueIds.Count() == 1 && c2AllocatedQueueIds.Count() == 1 && c3AllocatedQueueIds.Count() == 1 && c4AllocatedQueueIds.Count() == 1)
                {
                    _logger.Info(string.Format("Consumer load balance finished. Queue allocation result: c1:{0}, c2:{1}, c3:{2}, c4:{3}",
                        string.Join(",", c1AllocatedQueueIds),
                        string.Join(",", c2AllocatedQueueIds),
                        string.Join(",", c3AllocatedQueueIds),
                        string.Join(",", c4AllocatedQueueIds)));
                    waitHandle.Set();
                }
            }, 1000, 1000);

            waitHandle.WaitOne();
            scheduleService.ShutdownTask(taskId);
        }
Exemple #20
0
        static void InitializeEQueue()
        {
            ECommonConfiguration
                .Create()
                .UseAutofac()
                .RegisterCommonComponents()
                .UseLog4Net()
                .UseJsonNet()
                .RegisterUnhandledExceptionHandler()
                .RegisterEQueueComponents();

            var clusterName = ConfigurationManager.AppSettings["ClusterName"];
            var consumerName = ConfigurationManager.AppSettings["ConsumerName"];
            var consumerGroup = ConfigurationManager.AppSettings["ConsumerGroup"];
            var address = ConfigurationManager.AppSettings["NameServerAddress"];
            var topic = ConfigurationManager.AppSettings["Topic"];
            var nameServerAddress = string.IsNullOrEmpty(address) ? SocketUtils.GetLocalIPV4() : IPAddress.Parse(address);
            var clientCount = int.Parse(ConfigurationManager.AppSettings["ClientCount"]);
            var setting = new ConsumerSetting
            {
                ClusterName = clusterName,
                ConsumeFromWhere = ConsumeFromWhere.FirstOffset,
                MessageHandleMode = MessageHandleMode.Sequential,
                NameServerList = new List<IPEndPoint> { new IPEndPoint(nameServerAddress, 9493) }
            };
            var messageHandler = new MessageHandler();
            for (var i = 1; i <= clientCount; i++)
            {
                new Consumer(consumerGroup, setting, consumerName)
                    .Subscribe(topic)
                    .SetMessageHandler(messageHandler)
                    .Start();
            }
        }
Exemple #21
0
 public EventConsumer(string id, ConsumerSetting setting, string groupName, DomainEventHandledMessageSender domainEventHandledMessageSender)
 {
     _consumer = new Consumer(id, setting, string.IsNullOrEmpty(groupName) ? typeof(EventConsumer).Name + "Group" : groupName);
     _binarySerializer = ObjectContainer.Resolve<IBinarySerializer>();
     _eventTypeCodeProvider = ObjectContainer.Resolve<IEventTypeCodeProvider>();
     _eventProcessor = ObjectContainer.Resolve<IEventProcessor>();
     _messageContextDict = new ConcurrentDictionary<string, IMessageContext>();
     _domainEventHandledMessageSender = domainEventHandledMessageSender;
 }
 public ApplicationMessageConsumer(string groupName = null, ConsumerSetting setting = null)
 {
     _consumer = new Consumer(groupName ?? DefaultMessageConsumerGroup, setting ?? new ConsumerSetting
     {
         MessageHandleMode = MessageHandleMode.Sequential
     });
     _jsonSerializer = ObjectContainer.Resolve<IJsonSerializer>();
     _processor = ObjectContainer.Resolve<IMessageProcessor<ProcessingApplicationMessage, IApplicationMessage, bool>>();
     _typeNameProvider = ObjectContainer.Resolve<ITypeNameProvider>();
 }
 public PublishableExceptionConsumer(string id = null, string groupName = null, ConsumerSetting setting = null)
 {
     _consumer = new Consumer(groupName ?? DefaultExceptionConsumerGroup, setting ?? new ConsumerSetting
     {
         MessageHandleMode = MessageHandleMode.Sequential
     });
     _jsonSerializer = ObjectContainer.Resolve<IJsonSerializer>();
     _publishableExceptionProcessor = ObjectContainer.Resolve<IMessageProcessor<ProcessingPublishableExceptionMessage, IPublishableException, bool>>();
     _publishableExceptionTypeCodeProvider = ObjectContainer.Resolve<ITypeCodeProvider>();
 }
Exemple #24
0
 public Consumer(string id, ConsumerSetting setting, string groupName)
 {
     Id = id;
     Setting = setting ?? new ConsumerSetting();
     GroupName = groupName;
     _remotingClient = new SocketRemotingClient(Setting.BrokerAddress, Setting.BrokerPort);
     _binarySerializer = ObjectContainer.Resolve<IBinarySerializer>();
     _scheduleService = ObjectContainer.Resolve<IScheduleService>();
     _offsetStore = Setting.MessageModel == MessageModel.Clustering ? ObjectContainer.Resolve<IRemoteBrokerOffsetStore>() as IOffsetStore : ObjectContainer.Resolve<ILocalOffsetStore>() as IOffsetStore;
     _allocateMessageQueueStragegy = ObjectContainer.Resolve<IAllocateMessageQueueStrategy>();
     _logger = ObjectContainer.Resolve<ILoggerFactory>().Create(GetType().Name);
 }
 public DomainEventConsumer(string groupName = null, ConsumerSetting setting = null, bool sendEventHandledMessage = true)
 {
     _consumer = new Consumer(groupName ?? DefaultEventConsumerGroup, setting ?? new ConsumerSetting
     {
         MessageHandleMode = MessageHandleMode.Sequential
     });
     _sendReplyService = new SendReplyService();
     _jsonSerializer = ObjectContainer.Resolve<IJsonSerializer>();
     _eventSerializer = ObjectContainer.Resolve<IEventSerializer>();
     _processor = ObjectContainer.Resolve<IMessageProcessor<ProcessingDomainEventStreamMessage, DomainEventStreamMessage, bool>>();
     _logger = ObjectContainer.Resolve<ILoggerFactory>().Create(GetType().FullName);
     _sendEventHandledMessage = sendEventHandledMessage;
 }
        public CommandConsumer(string name, EQueueClientsConsumers.ConsumerSetting consumerSetting, string groupName,
                               string subscribeTopic, string brokerAddress, int producerBrokerPort,
                               IHandlerProvider handlerProvider)
            : base(name, consumerSetting, groupName, subscribeTopic)
        {
            HandlerProvider = handlerProvider;
            var producerSetting = new EQueueClientsProducers.ProducerSetting();

            producerSetting.BrokerAddress = brokerAddress;
            producerSetting.BrokerPort    = producerBrokerPort;
            Producer = new EQueueClientsProducers.Producer(string.Format("{0}-Reply-Producer", name), producerSetting);
            CommandConsumers.Add(this);
        }
        public void Start()
        {
            var setting = new EQueueConsumers.ConsumerSetting
            {
                AutoPull           = false,
                ConsumeFromWhere   = EQueueMessages.ConsumeFromWhere.FirstOffset,
                BrokerAddress      = new IPEndPoint(IPAddress.Parse(BrokerAddress), ConsumerPort),
                BrokerAdminAddress = new IPEndPoint(IPAddress.Parse(BrokerAddress), AdminPort)
            };

            Consumer = new EQueueConsumers.Consumer(GroupId, setting)
                       .Subscribe(Topic)
                       .Start();
        }
        public override void Start()
        {
            var setting = new EQueueConsumers.ConsumerSetting
            {
                AutoPull         = false,
                ConsumeFromWhere = ConsumerConfig.AutoOffsetReset == AutoOffsetReset.Smallest || ConsumerConfig.AutoOffsetReset == AutoOffsetReset.Earliest ? EQueueMessages.ConsumeFromWhere.FirstOffset : EQueueMessages.ConsumeFromWhere.LastOffset,
                ClusterName      = ClusterName,
                NameServerList   = NameServerList
            };

            Consumer = new EQueueConsumers.Consumer(GroupId, setting, ConsumerId);
            Topics.ForEach(topic => Consumer.Subscribe(topic));
            Consumer.Start();
            base.Start();
        }
Exemple #29
0
        static void Main(string[] args)
        {
            InitializeEQueue();

            var messageHandler = new MessageHandler();
            var consumerSetting = new ConsumerSetting
            {
                HeartbeatBrokerInterval = 1000,
                UpdateTopicQueueCountInterval = 1000,
                RebalanceInterval = 1000,
                ConsumeFromWhere = ConsumeFromWhere.FirstOffset
            };
            var consumer = new Consumer("SampleConsumer@" + ObjectId.GenerateNewStringId(), "SampleGroup", consumerSetting).Subscribe("SampleTopic").SetMessageHandler(messageHandler).Start();
            Console.ReadLine();
        }
Exemple #30
0
        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;
        }
Exemple #31
0
 public Consumer(string id, string groupName, ConsumerSetting setting)
 {
     if (id == null)
     {
         throw new ArgumentNullException("id");
     }
     if (groupName == null)
     {
         throw new ArgumentNullException("groupName");
     }
     Id                            = id;
     GroupName                     = groupName;
     Setting                       = setting ?? new ConsumerSetting();
     _remotingClient               = new SocketRemotingClient(Setting.BrokerAddress, Setting.BrokerPort);
     _binarySerializer             = ObjectContainer.Resolve <IBinarySerializer>();
     _scheduleService              = ObjectContainer.Resolve <IScheduleService>();
     _localOffsetStore             = ObjectContainer.Resolve <ILocalOffsetStore>();
     _allocateMessageQueueStragegy = ObjectContainer.Resolve <IAllocateMessageQueueStrategy>();
     _logger                       = ObjectContainer.Resolve <ILoggerFactory>().Create(GetType().FullName);
 }
Exemple #32
0
 public Consumer(string id, string groupName, ConsumerSetting setting)
 {
     if (id == null)
     {
         throw new ArgumentNullException("id");
     }
     if (groupName == null)
     {
         throw new ArgumentNullException("groupName");
     }
     Id = id;
     GroupName = groupName;
     Setting = setting ?? new ConsumerSetting();
     _remotingClient = new SocketRemotingClient(Setting.BrokerAddress, Setting.BrokerPort);
     _binarySerializer = ObjectContainer.Resolve<IBinarySerializer>();
     _scheduleService = ObjectContainer.Resolve<IScheduleService>();
     _localOffsetStore = ObjectContainer.Resolve<ILocalOffsetStore>();
     _allocateMessageQueueStragegy = ObjectContainer.Resolve<IAllocateMessageQueueStrategy>();
     _logger = ObjectContainer.Resolve<ILoggerFactory>().Create(GetType().FullName);
 }
Exemple #33
0
        public static ENodeConfiguration UseEQueue(this ENodeConfiguration enodeConfiguration)
        {
            var configuration = enodeConfiguration.GetCommonConfiguration();

            configuration.RegisterEQueueComponents();

            var eventConsumerSetting = new ConsumerSetting
            {
                HeartbeatBrokerInterval = 1000,
                UpdateTopicQueueCountInterval = 1000,
                RebalanceInterval = 1000,
                MessageHandleMode = MessageHandleMode.Sequential
            };

            _domainEventHandledMessageSender = new DomainEventHandledMessageSender();
            _eventConsumer = new EventConsumer(eventConsumerSetting, _domainEventHandledMessageSender);

            _eventConsumer.Subscribe("NoteEventTopic1");
            _eventConsumer.Subscribe("NoteEventTopic2");

            return enodeConfiguration;
        }
Exemple #34
0
        public void Start()
        {
            var setting = new EQueueConsumers.ConsumerSetting
            {
                AutoPull         = false,
                ConsumeFromWhere = (_consumerConfig.AutoOffsetReset == AutoOffsetReset.Smallest || _consumerConfig.AutoOffsetReset == AutoOffsetReset.Earliest) ?
                                   EQueueMessages.ConsumeFromWhere.FirstOffset : EQueueMessages.ConsumeFromWhere.LastOffset,
                ClusterName    = ClusterName,
                NameServerList = NameServerList
            };

            Consumer = new EQueueConsumers.Consumer(GroupId, setting)
                       .Subscribe(Topic)
                       .Start();
            _cancellationTokenSource = new CancellationTokenSource();
            _consumerTask            = Task.Factory.StartNew(cs => ReceiveMessages(cs as CancellationTokenSource,
                                                                                   _onMessageReceived),
                                                             _cancellationTokenSource,
                                                             _cancellationTokenSource.Token,
                                                             TaskCreationOptions.LongRunning,
                                                             TaskScheduler.Default);
        }
Exemple #35
0
        static void InitializeEQueue()
        {
            ECommonConfiguration
                .Create()
                .UseAutofac()
                .RegisterCommonComponents()
                .UseLog4Net()
                .UseJsonNet()
                .RegisterUnhandledExceptionHandler()
                .RegisterEQueueComponents();

            var setting = new ConsumerSetting
            {
                ConsumeFromWhere = ConsumeFromWhere.FirstOffset,
                MessageHandleMode = MessageHandleMode.Sequential,
                BrokerAddress = new IPEndPoint(SocketUtils.GetLocalIPV4(), 5001),
                BrokerAdminAddress = new IPEndPoint(SocketUtils.GetLocalIPV4(), 5002)
            };
            new Consumer("group1", setting)
                .Subscribe("topic1")
                .SetMessageHandler(new MessageHandler())
                .Start();
        }
Exemple #36
0
 public CommandBus(string name, ICommandHandlerProvider handlerProvider,
                   ILinearCommandManager linearCommandManager,
                   string brokerAddress,
                   int producerBrokerPort,
                   EQueueClientsConsumers.ConsumerSetting consumerSetting,
                   string groupName,
                   string replyTopic,
                   string commandTopic,
                   bool inProc)
     : base(name, consumerSetting, groupName, replyTopic)
 {
     CommandStateQueue    = Hashtable.Synchronized(new Hashtable());
     ToBeSentCommandQueue = new BlockingCollection <MessageContext>();
     HandlerProvider      = handlerProvider;
     LinearCommandManager = linearCommandManager;
     CommandTopic         = commandTopic;
     ReplyTopic           = replyTopic;
     InProc          = inProc;
     ProducerSetting = new EQueueClientsProducers.ProducerSetting();
     ProducerSetting.BrokerAddress = brokerAddress;
     ProducerSetting.BrokerPort    = producerBrokerPort;
     ProducerName = name;
 }
Exemple #37
0
        public Consumer(string groupName, ConsumerSetting setting, string consumerName = null)
        {
            if (groupName == null)
            {
                throw new ArgumentNullException("groupName");
            }

            Name      = consumerName;
            GroupName = groupName;
            Setting   = setting ?? new ConsumerSetting();

            if (Setting.NameServerList == null || Setting.NameServerList.Count() == 0)
            {
                throw new Exception("Name server address is not specified.");
            }

            _subscriptionTopics = new Dictionary <string, HashSet <string> >();
            _jsonSerializer     = ObjectContainer.Resolve <IJsonSerializer>();
            _logger             = ObjectContainer.Resolve <ILoggerFactory>().Create(GetType().FullName);

            var clientSetting = new ClientSetting
            {
                ClientName            = Name,
                ClusterName           = Setting.ClusterName,
                NameServerList        = Setting.NameServerList,
                SocketSetting         = Setting.SocketSetting,
                OnlyFindMasterBroker  = true,
                SendHeartbeatInterval = Setting.HeartbeatBrokerInterval,
                RefreshBrokerAndTopicRouteInfoInterval = Setting.RefreshBrokerAndTopicRouteInfoInterval
            };

            _clientService              = new ClientService(clientSetting, null, this);
            _pullMessageService         = new PullMessageService(this, _clientService);
            _commitConsumeOffsetService = new CommitConsumeOffsetService(this, _clientService);
            _rebalanceService           = new RebalanceService(this, _clientService, _pullMessageService, _commitConsumeOffsetService);
        }
Exemple #38
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();
            }
        }
        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;
        }
Exemple #40
0
 public Consumer(ConsumerSetting setting, string name, string groupName)
     : this(string.Format("{0}@{1}@{2}", SocketUtils.GetLocalIPV4(), string.IsNullOrEmpty(name) ? typeof(Consumer).Name : name, ObjectId.GenerateNewId()), setting, groupName)
 {
 }
Exemple #41
0
 public EventConsumer(ConsumerSetting setting, string groupName, DomainEventHandledMessageSender domainEventHandledMessageSender)
     : this(setting, null, groupName, domainEventHandledMessageSender)
 {
 }
Exemple #42
0
 public EventConsumer(ConsumerSetting setting, string name, string groupName, DomainEventHandledMessageSender domainEventHandledMessageSender)
     : this(string.Format("{0}@{1}@{2}", SocketUtils.GetLocalIPV4(), string.IsNullOrEmpty(name) ? typeof(EventConsumer).Name : name, ObjectId.GenerateNewId()), setting, groupName, domainEventHandledMessageSender)
 {
 }