Ejemplo n.º 1
0
        public void ExecuteActionToAllClusterBrokers(string clusterName, Action <SocketRemotingClient> action)
        {
            var request = new GetClusterBrokersRequest
            {
                ClusterName    = clusterName,
                OnlyFindMaster = true
            };
            var endpointList       = _nameServerController.ClusterManager.GetClusterBrokers(request).Select(x => x.AdminAddress.ToEndPoint());
            var remotingClientList = RemotingClientUtils.CreateRemotingClientList(endpointList, _nameServerController.Setting.SocketSetting);

            foreach (var remotingClient in remotingClientList)
            {
                remotingClient.Start();
            }

            try
            {
                foreach (var remotingClient in remotingClientList)
                {
                    action(remotingClient);
                }
            }
            finally
            {
                foreach (var remotingClient in remotingClientList)
                {
                    remotingClient.Shutdown();
                }
            }
        }
Ejemplo n.º 2
0
        public ClientService(ClientSetting setting, Producer producer, Consumer consumer)
        {
            Ensure.NotNull(setting, "setting");
            if (producer == null && consumer == null)
            {
                throw new ArgumentException("producer or consumer must set at least one of them.");
            }
            else if (producer != null && consumer != null)
            {
                throw new ArgumentException("producer or consumer cannot set both of them.");
            }

            Interlocked.Increment(ref _instanceNumber);

            _producer              = producer;
            _consumer              = consumer;
            _setting               = setting;
            _clientId              = BuildClientId(setting.ClientName);
            _brokerConnectionDict  = new ConcurrentDictionary <string, BrokerConnection>();
            _topicMessageQueueDict = new ConcurrentDictionary <string, IList <MessageQueue> >();
            _binarySerializer      = ObjectContainer.Resolve <IBinarySerializer>();
            _jsonSerializer        = ObjectContainer.Resolve <IJsonSerializer>();
            _scheduleService       = ObjectContainer.Resolve <IScheduleService>();
            _logger = ObjectContainer.Resolve <ILoggerFactory>().Create(GetType().FullName);
            _nameServerRemotingClientList = RemotingClientUtils.CreateRemotingClientList(_setting.NameServerList, _setting.SocketSetting).ToList();
        }
Ejemplo n.º 3
0
        private BrokerController(BrokerSetting setting)
        {
            Setting = setting ?? new BrokerSetting();

            Setting.BrokerInfo.Valid();
            if (Setting.NameServerList == null || Setting.NameServerList.Count() == 0)
            {
                throw new ArgumentException("NameServerList is empty.");
            }

            _latestMessageIds               = new string[Setting.LatestMessageShowCount];
            _producerManager                = ObjectContainer.Resolve <ProducerManager>();
            _consumerManager                = ObjectContainer.Resolve <ConsumerManager>();
            _messageStore                   = ObjectContainer.Resolve <IMessageStore>();
            _consumeOffsetStore             = ObjectContainer.Resolve <IConsumeOffsetStore>();
            _queueStore                     = ObjectContainer.Resolve <IQueueStore>();
            _getTopicConsumeInfoListService = ObjectContainer.Resolve <GetTopicConsumeInfoListService>();
            _getConsumerListService         = ObjectContainer.Resolve <GetConsumerListService>();
            _scheduleService                = ObjectContainer.Resolve <IScheduleService>();
            _binarySerializer               = ObjectContainer.Resolve <IBinarySerializer>();
            _suspendedPullRequestManager    = ObjectContainer.Resolve <SuspendedPullRequestManager>();
            _chunkReadStatisticService      = ObjectContainer.Resolve <IChunkStatisticService>();
            _tpsStatisticService            = ObjectContainer.Resolve <ITpsStatisticService>();

            _producerSocketRemotingServer = new SocketRemotingServer("EQueue.Broker.ProducerRemotingServer", Setting.BrokerInfo.ProducerAddress.ToEndPoint(), Setting.SocketSetting);
            _consumerSocketRemotingServer = new SocketRemotingServer("EQueue.Broker.ConsumerRemotingServer", Setting.BrokerInfo.ConsumerAddress.ToEndPoint(), Setting.SocketSetting);
            _adminSocketRemotingServer    = new SocketRemotingServer("EQueue.Broker.AdminRemotingServer", Setting.BrokerInfo.AdminAddress.ToEndPoint(), Setting.SocketSetting);

            _logger = ObjectContainer.Resolve <ILoggerFactory>().Create(GetType().FullName);
            _producerSocketRemotingServer.RegisterConnectionEventListener(new ProducerConnectionEventListener(this));
            _consumerSocketRemotingServer.RegisterConnectionEventListener(new ConsumerConnectionEventListener(this));
            RegisterRequestHandlers();

            _service = new ConsoleEventHandlerService();
            _service.RegisterClosingEventHandler(eventCode => { Shutdown(); });
            _nameServerRemotingClientList = RemotingClientUtils.CreateRemotingClientList(Setting.NameServerList, Setting.SocketSetting).ToList();
        }