コード例 #1
0
ファイル: Consumer.cs プロジェクト: Aaron-Liu/equeue
        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);
        }
コード例 #2
0
ファイル: Consumer.cs プロジェクト: ywscr/equeue
        public Consumer(string groupName, ConsumerSetting setting, string consumerName = "DefaultConsumer")
        {
            Name      = consumerName;
            GroupName = groupName ?? throw new ArgumentNullException("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);

            TaskScheduler.UnobservedTaskException += (sender, ex) =>
            {
                _logger.ErrorFormat("UnobservedTaskException occurred.", ex);
            };
        }