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 = endpointList.ToRemotingClientList(_nameServerController.Setting.Name, _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();
                }
            }
        }
Beispiel #2
0
        public IList <BrokerStatusInfo> GetClusterBrokerStatusInfos(GetClusterBrokersRequest request)
        {
            lock (_lockObj)
            {
                var     returnList = new List <Broker>();
                Cluster cluster;
                if (string.IsNullOrEmpty(request.ClusterName) || !_clusterDict.TryGetValue(request.ClusterName, out cluster))
                {
                    return(returnList.Select(x => new BrokerStatusInfo
                    {
                        BrokerInfo = x.BrokerInfo,
                        TotalSendThroughput = x.TotalSendThroughput,
                        TotalConsumeThroughput = x.TotalConsumeThroughput,
                        TotalUnConsumedMessageCount = x.TotalUnConsumedMessageCount
                    }).ToList());
                }

                foreach (var brokerGroup in cluster.BrokerGroups.Values)
                {
                    foreach (var broker in brokerGroup.Brokers.Values)
                    {
                        if (request.OnlyFindMaster && broker.BrokerInfo.BrokerRole != (int)BrokerRole.Master)
                        {
                            continue;
                        }
                        if (!string.IsNullOrEmpty(request.Topic))
                        {
                            if (broker.TopicQueueInfoList.Any(x => x.Topic == request.Topic))
                            {
                                returnList.Add(broker);
                            }
                        }
                        else
                        {
                            returnList.Add(broker);
                        }
                    }
                }

                returnList.Sort((x, y) =>
                {
                    return(string.Compare(x.BrokerInfo.BrokerName, y.BrokerInfo.BrokerName));
                });

                return(returnList.Select(x => new BrokerStatusInfo
                {
                    BrokerInfo = x.BrokerInfo,
                    TotalSendThroughput = x.TotalSendThroughput,
                    TotalConsumeThroughput = x.TotalConsumeThroughput,
                    TotalUnConsumedMessageCount = x.TotalUnConsumedMessageCount
                }).ToList());
            }
        }
Beispiel #3
0
        public IList <BrokerInfo> GetClusterBrokers(GetClusterBrokersRequest request)
        {
            lock (_lockObj)
            {
                var     returnList = new List <Broker>();
                Cluster cluster;
                if (string.IsNullOrEmpty(request.ClusterName) || !_clusterDict.TryGetValue(request.ClusterName, out cluster))
                {
                    return(returnList.Select(x => x.BrokerInfo).ToList());
                }

                foreach (var brokerGroup in cluster.BrokerGroups.Values)
                {
                    foreach (var broker in brokerGroup.Brokers.Values)
                    {
                        if (request.OnlyFindMaster && broker.BrokerInfo.BrokerRole != (int)BrokerRole.Master)
                        {
                            continue;
                        }
                        if (!string.IsNullOrEmpty(request.Topic))
                        {
                            if (broker.TopicQueueInfoList.Any(x => x.Topic == request.Topic))
                            {
                                returnList.Add(broker);
                            }
                        }
                        else
                        {
                            returnList.Add(broker);
                        }
                    }
                }

                returnList.Sort((x, y) =>
                {
                    if (x.FirstRegisteredTime.Ticks > y.FirstRegisteredTime.Ticks)
                    {
                        return(1);
                    }
                    else if (x.FirstRegisteredTime.Ticks < y.FirstRegisteredTime.Ticks)
                    {
                        return(-1);
                    }
                    return(0);
                });

                return(returnList.Select(x => x.BrokerInfo).ToList());
            }
        }
        private IList <BrokerInfo> GetClusterBrokerList()
        {
            var nameServerRemotingClient = GetAvailableNameServerRemotingClient();
            var request = new GetClusterBrokersRequest
            {
                ClusterName    = _setting.ClusterName,
                OnlyFindMaster = _setting.OnlyFindMasterBroker
            };
            var data             = _binarySerializer.Serialize(request);
            var remotingRequest  = new RemotingRequest((int)NameServerRequestCode.GetClusterBrokers, data);
            var remotingResponse = nameServerRemotingClient.InvokeSync(remotingRequest, 5 * 1000);

            if (remotingResponse.ResponseCode != ResponseCode.Success)
            {
                throw new Exception(string.Format("Get cluster brokers from name server failed, clusterName: {0}, nameServerAddress: {1}, remoting response code: {2}, errorMessage: {3}", request.ClusterName, nameServerRemotingClient.ServerEndPoint.ToAddress(), remotingResponse.ResponseCode, Encoding.UTF8.GetString(remotingResponse.ResponseBody)));
            }
            return(_binarySerializer.Deserialize <IList <BrokerInfo> >(remotingResponse.ResponseBody));
        }