Ejemplo n.º 1
0
        private async Task RegisterBrokerToAllNameServers()
        {
            var totalSendThroughput    = _tpsStatisticService.GetTotalSendThroughput();
            var totalConsumeThroughput = _tpsStatisticService.GetTotalConsumeThroughput();
            var topicQueueInfoList     = _queueStore.GetTopicQueueInfoList();
            var topicConsumeInfoList   = _getTopicConsumeInfoListService.GetAllTopicConsumeInfoList().ToList();
            var producerList           = _producerManager.GetAllProducers().ToList();
            var consumerList           = _getConsumerListService.GetAllConsumerList().ToList();
            var request = new BrokerRegistrationRequest
            {
                BrokerInfo                  = Setting.BrokerInfo,
                TotalSendThroughput         = totalSendThroughput,
                TotalConsumeThroughput      = totalConsumeThroughput,
                TotalUnConsumedMessageCount = _queueStore.GetTotalUnConusmedMessageCount(),
                TopicQueueInfoList          = topicQueueInfoList,
                TopicConsumeInfoList        = topicConsumeInfoList,
                ProducerList                = producerList,
                ConsumerList                = consumerList
            };

            foreach (var remotingClient in _nameServerRemotingClientList)
            {
                await RegisterBrokerToNameServer(request, remotingClient);
            }
        }
Ejemplo n.º 2
0
        private void RegisterBrokerToNameServer(BrokerRegistrationRequest request, SocketRemotingClient remotingClient, bool isSync = false)
        {
            var nameServerAddress = remotingClient.ServerEndPoint.ToAddress();

            try
            {
                var data            = _binarySerializer.Serialize(request);
                var remotingRequest = new RemotingRequest((int)NameServerRequestCode.RegisterBroker, data);
                if (isSync)
                {
                    var response = remotingClient.InvokeSync(remotingRequest, 10000);
                    if (response.ResponseCode != ResponseCode.Success)
                    {
                        throw new Exception("Register broker to name server failed.");
                    }
                }
                else
                {
                    remotingClient.InvokeOneway(remotingRequest);
                }
            }
            catch (Exception ex)
            {
                _logger.Error(string.Format("Register broker to name server has exception, brokerInfo: {0}, nameServerAddress: {1}", request.BrokerInfo, nameServerAddress), ex);
            }
        }
Ejemplo n.º 3
0
        public void RegisterBroker(ITcpConnection connection, BrokerRegistrationRequest request)
        {
            using (_asyncLock.Lock())
            {
                var brokerInfo = request.BrokerInfo;
                var cluster    = _clusterDict.GetOrAdd(brokerInfo.ClusterName, x => new Cluster {
                    ClusterName = x
                });
                var brokerGroup = cluster.BrokerGroups.GetOrAdd(brokerInfo.GroupName, x => new BrokerGroup {
                    GroupName = x
                });
                Broker broker;
                if (!brokerGroup.Brokers.TryGetValue(brokerInfo.BrokerName, out broker))
                {
                    var connectionId = connection.RemotingEndPoint.ToAddress();
                    broker = new Broker
                    {
                        BrokerInfo                  = request.BrokerInfo,
                        TotalSendThroughput         = request.TotalSendThroughput,
                        TotalConsumeThroughput      = request.TotalConsumeThroughput,
                        TotalUnConsumedMessageCount = request.TotalUnConsumedMessageCount,
                        TopicQueueInfoList          = request.TopicQueueInfoList,
                        TopicConsumeInfoList        = request.TopicConsumeInfoList,
                        ProducerList                = request.ProducerList,
                        ConsumerList                = request.ConsumerList,
                        Connection                  = connection,
                        ConnectionId                = connectionId,
                        LastActiveTime              = DateTime.Now,
                        FirstRegisteredTime         = DateTime.Now,
                        Group = brokerGroup
                    };
                    if (brokerGroup.Brokers.TryAdd(brokerInfo.BrokerName, broker))
                    {
                        _logger.InfoFormat("Registered new broker, brokerInfo: {0}", _jsonSerializer.Serialize(brokerInfo));
                    }
                }
                else
                {
                    broker.LastActiveTime              = DateTime.Now;
                    broker.TotalSendThroughput         = request.TotalSendThroughput;
                    broker.TotalConsumeThroughput      = request.TotalConsumeThroughput;
                    broker.TotalUnConsumedMessageCount = request.TotalUnConsumedMessageCount;

                    if (!broker.BrokerInfo.IsEqualsWith(request.BrokerInfo))
                    {
                        var logInfo = string.Format("Broker basicInfo changed, old: {0}, new: {1}", broker.BrokerInfo, request.BrokerInfo);
                        broker.BrokerInfo = request.BrokerInfo;
                        _logger.Info(logInfo);
                    }

                    broker.TopicQueueInfoList   = request.TopicQueueInfoList;
                    broker.TopicConsumeInfoList = request.TopicConsumeInfoList;
                    broker.ProducerList         = request.ProducerList;
                    broker.ConsumerList         = request.ConsumerList;

                    _logger.InfoFormat("Broker heartbeat received, brokerInfo: {0}", broker.BrokerInfo);
                }
            }
        }
Ejemplo n.º 4
0
        public RemotingResponse RegisterBroker(BrokerRegistrationRequest model)
        {
            var netsession = Session as INetSession;

            if (netsession != null)
            {
                var server = netsession.Server as CenterServer;
                server?.ClusterManager.RegisterBroker(Session, model);
            }
            return(new RemotingResponse());
        }
Ejemplo n.º 5
0
        private void RegisterBrokerToNameServer(BrokerRegistrationRequest request, SocketRemotingClient remotingClient)
        {
            var nameServerAddress = remotingClient.ServerEndPoint.ToAddress();

            try
            {
                var data             = _binarySerializer.Serialize(request);
                var remotingRequest  = new RemotingRequest((int)NameServerRequestCode.RegisterBroker, data);
                var remotingResponse = remotingClient.InvokeSync(remotingRequest, 5 * 1000);
                if (remotingResponse.ResponseCode != ResponseCode.Success)
                {
                    _logger.Error(string.Format("Register broker to name server failed, brokerInfo: {0}, nameServerAddress: {1}, remoting response code: {2}, errorMessage: {3}", request.BrokerInfo, nameServerAddress, remotingResponse.ResponseCode, Encoding.UTF8.GetString(remotingResponse.ResponseBody)));
                }
            }
            catch (Exception ex)
            {
                _logger.Error(string.Format("Register broker to name server has exception, brokerInfo: {0}, nameServerAddress: {1}", request.BrokerInfo, nameServerAddress), ex);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="apiSession"></param>
        /// <param name="request"></param>
        public void RegisterBroker(IApiSession apiSession, BrokerRegistrationRequest request)
        {
            lock (_lockObj)
            {
                var brokerInfo = request.BrokerInfo;
                var cluster    = _clusterDict.GetOrAdd(brokerInfo.ClusterName, x => new Cluster {
                    ClusterName = x
                });
                var brokerGroup = cluster.BrokerGroups.GetOrAdd(brokerInfo.GroupName, x => new BrokerGroup {
                    GroupName = x
                });
                Broker broker;
                if (!brokerGroup.Brokers.TryGetValue(brokerInfo.BrokerName, out broker))
                {
                    var netSession = apiSession as INetSession;
                    if (netSession != null)
                    {
                        var connectionId = netSession.Remote.EndPoint.ToAddress();
                        broker = new Broker
                        {
                            BrokerInfo                  = request.BrokerInfo,
                            TotalSendThroughput         = request.TotalSendThroughput,
                            TotalConsumeThroughput      = request.TotalConsumeThroughput,
                            TotalUnConsumedMessageCount = request.TotalUnConsumedMessageCount,
                            TopicQueueInfoList          = request.TopicQueueInfoList,
                            TopicConsumeInfoList        = request.TopicConsumeInfoList,
                            ProducerList                = request.ProducerList,
                            ConsumerList                = request.ConsumerList,
                            ApiSession                  = apiSession,
                            ConnectionId                = connectionId,
                            LastActiveTime              = DateTime.Now,
                            FirstRegisteredTime         = DateTime.Now,
                            Group = brokerGroup
                        };
                        if (brokerGroup.Brokers.TryAdd(brokerInfo.BrokerName, broker))
                        {
                            _centerServer.Log.Info("Registered new broker, brokerInfo: {0}", brokerInfo.ToJson());
                        }
                    }
                    else
                    {
                        _centerServer.Log.Error("Registered broker Erro, brokerInfo: {0}", brokerInfo.ToJson());
                    }
                }
                else
                {
                    broker.LastActiveTime              = DateTime.Now;
                    broker.TotalSendThroughput         = request.TotalSendThroughput;
                    broker.TotalConsumeThroughput      = request.TotalConsumeThroughput;
                    broker.TotalUnConsumedMessageCount = request.TotalUnConsumedMessageCount;

                    if (!broker.BrokerInfo.IsEqualsWith(request.BrokerInfo))
                    {
                        _centerServer.Log.Info("Broker basicInfo changed, old: {0}, new: {1}", broker.BrokerInfo, request.BrokerInfo);
                        broker.BrokerInfo = request.BrokerInfo;
                    }

                    broker.TopicQueueInfoList   = request.TopicQueueInfoList;
                    broker.TopicConsumeInfoList = request.TopicConsumeInfoList;
                    broker.ProducerList         = request.ProducerList;
                    broker.ConsumerList         = request.ConsumerList;
                }
            }
        }