示例#1
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);
        }
示例#2
0
        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);
        }
示例#3
0
 public RebalanceService(Consumer consumer, ClientService clientService, PullMessageService pullMessageService, CommitConsumeOffsetService commitConsumeOffsetService)
 {
     _consumer        = consumer;
     _clientService   = clientService;
     _clientId        = clientService.GetClientId();
     _pullRequestDict = new ConcurrentDictionary <string, PullRequest>();
     _allocateMessageQueueStragegy = ObjectContainer.Resolve <IAllocateMessageQueueStrategy>();
     _pullMessageService           = pullMessageService;
     _commitConsumeOffsetService   = commitConsumeOffsetService;
     _binarySerializer             = ObjectContainer.Resolve <IBinarySerializer>();
     _scheduleService = ObjectContainer.Resolve <IScheduleService>();
     _logger          = ObjectContainer.Resolve <ILoggerFactory>().Create(GetType().FullName);
 }
示例#4
0
 public RebalanceService(Consumer consumer, ClientService clientService, PullMessageService pullMessageService, CommitConsumeOffsetService commitConsumeOffsetService)
 {
     _consumer = consumer;
     _clientService = clientService;
     _clientId = clientService.GetClientId();
     _pullRequestDict = new ConcurrentDictionary<string, PullRequest>();
     _allocateMessageQueueStragegy = ObjectContainer.Resolve<IAllocateMessageQueueStrategy>();
     _pullMessageService = pullMessageService;
     _commitConsumeOffsetService = commitConsumeOffsetService;
     _binarySerializer = ObjectContainer.Resolve<IBinarySerializer>();
     _scheduleService = ObjectContainer.Resolve<IScheduleService>();
     _logger = ObjectContainer.Resolve<ILoggerFactory>().Create(GetType().FullName);
 }