Пример #1
0
 public SendResult(SendStatus sendStatus, long messageOffset, MessageQueue messageQueue, long queueOffset)
 {
     SendStatus = sendStatus;
     MessageOffset = messageOffset;
     MessageQueue = messageQueue;
     QueueOffset = queueOffset;
 }
Пример #2
0
 public PullRequest(string consumerId, string groupName, MessageQueue messageQueue, long nextConsumeOffset)
 {
     ConsumerId = consumerId;
     GroupName = groupName;
     MessageQueue = messageQueue;
     NextConsumeOffset = nextConsumeOffset;
     ProcessQueue = new ProcessQueue();
 }
Пример #3
0
 public void UpdateQueueOffset(string groupName, MessageQueue messageQueue, long queueOffset)
 {
     var queueOffsetDict = _dict.GetOrAdd(groupName, new ConcurrentDictionary<string, long>());
     var key = string.Format("{0}-{1}", messageQueue.Topic, messageQueue.QueueId);
     queueOffsetDict.AddOrUpdate(key, queueOffset, (currentKey, oldOffset) =>
     {
         return queueOffset > oldOffset ? queueOffset : oldOffset;
     });
 }
Пример #4
0
 public PullRequest(string consumerId, string groupName, MessageQueue messageQueue, long nextConsumeOffset, HashSet<string> tags)
 {
     ConsumerId = consumerId;
     GroupName = groupName;
     MessageQueue = messageQueue;
     NextConsumeOffset = nextConsumeOffset;
     ProcessQueue = new ProcessQueue();
     Tags = tags ?? new HashSet<string>();
 }
Пример #5
0
 public long GetQueueOffset(string groupName, MessageQueue messageQueue)
 {
     ConcurrentDictionary<string, long> queueOffsetDict;
     if (_dict.TryGetValue(groupName, out queueOffsetDict))
     {
         long queueOffset;
         if (queueOffsetDict.TryGetValue(string.Format("{0}-{1}", messageQueue.Topic, messageQueue.QueueId), out queueOffset))
         {
             return queueOffset;
         }
     }
     return -1;
 }
Пример #6
0
        public PullRequest(
            string consumerId,
            string groupName,
            MessageQueue messageQueue,
            SocketRemotingClient remotingClient,
            MessageHandleMode messageHandleMode,
            IMessageHandler messageHandler,
            IOffsetStore offsetStore,
            PullRequestSetting setting)
        {
            ConsumerId = consumerId;
            GroupName = groupName;
            MessageQueue = messageQueue;
            ProcessQueue = new ProcessQueue();

            _queueOffset = -1;
            _remotingClient = remotingClient;
            _setting = setting;
            _messageHandleMode = messageHandleMode;
            _messageHandler = messageHandler;
            _offsetStore = offsetStore;
            _messageQueue = new BlockingCollection<WrappedMessage>(new ConcurrentQueue<WrappedMessage>());
            _handlingMessageDict = new ConcurrentDictionary<long, WrappedMessage>();
            _pullMessageWorker = new Worker(() =>
            {
                try
                {
                    PullMessage();
                }
                catch (Exception ex)
                {
                    if (!_stoped)
                    {
                        _logger.Error(string.Format("[{0}]: PullMessage has unknown exception. PullRequest: {1}.", ConsumerId, this), ex);
                    }
                }
            });
            _handleMessageWorker = new Worker(HandleMessage);
            _binarySerializer = ObjectContainer.Resolve<IBinarySerializer>();
            _logger = ObjectContainer.Resolve<ILoggerFactory>().Create(GetType().Name);
        }
 public void Persist(MessageQueue messageQueue)
 {
 }
 public long ReadOffset(MessageQueue messageQueue, OffsetReadType readType)
 {
     return 0L;
 }
Пример #9
0
 public SendMessageResponse(long messageOffset, MessageQueue messageQueue, long queueOffset)
 {
     MessageOffset = messageOffset;
     MessageQueue = messageQueue;
     QueueOffset = queueOffset;
 }
Пример #10
0
        private void RefreshTopicRouteInfo()
        {
            lock (_lockObj)
            {
                foreach (var entry in _topicMessageQueueDict)
                {
                    var topic = entry.Key;
                    var oldMessageQueueList = entry.Value;
                    var topicRouteInfoList = GetTopicRouteInfoList(topic);
                    var newMessageQueueList = new List<MessageQueue>();

                    foreach (var topicRouteInfo in topicRouteInfoList)
                    {
                        foreach (var queueId in topicRouteInfo.QueueInfo)
                        {
                            var messageQueue = new MessageQueue(topicRouteInfo.BrokerInfo.BrokerName, topic, queueId);
                            newMessageQueueList.Add(messageQueue);
                        }
                    }
                    SortMessageQueues(newMessageQueueList);

                    var newMessageQueueJson = _jsonSerializer.Serialize(newMessageQueueList);
                    var oldMessageQueueJson = _jsonSerializer.Serialize(oldMessageQueueList);

                    if (oldMessageQueueJson != newMessageQueueJson)
                    {
                        _topicMessageQueueDict[topic] = newMessageQueueList;
                        _logger.InfoFormat("Topic routeInfo changed, topic: {0}, newRouteInfo: {1}, oldRouteInfo: {2}", topic, newMessageQueueJson, oldMessageQueueJson);
                    }
                }
            }
        }
Пример #11
0
        private bool TryGetAvailableMessageQueue(Message message, string routingKey, out MessageQueue messageQueue, out BrokerConnection brokerConnection)
        {
            messageQueue = null;
            brokerConnection = null;
            var retryCount = 0;

            while (retryCount <= Setting.SendMessageMaxRetryCount)
            {
                messageQueue = GetAvailableMessageQueue(message, routingKey);
                if (messageQueue == null)
                {
                    if (retryCount == 0)
                    {
                        _logger.ErrorFormat("No available message queue for topic [{0}]", message.Topic);
                    }
                    else
                    {
                        _logger.ErrorFormat("No available message queue for topic [{0}], retryTimes: {1}", message.Topic, retryCount);
                    }
                }
                else
                {
                    brokerConnection = _clientService.GetBrokerConnection(messageQueue.BrokerName);
                    if (brokerConnection != null && brokerConnection.RemotingClient.IsConnected)
                    {
                        return true;
                    }
                    if (retryCount == 0)
                    {
                        _logger.ErrorFormat("Broker is unavailable for queue [{0}]", messageQueue);
                    }
                    else
                    {
                        _logger.ErrorFormat("Broker is unavailable for queue [{0}], retryTimes: {1}", message.Topic, retryCount);
                    }
                }
                retryCount++;
            }

            return false;
        }
Пример #12
0
 public virtual void PersistQueueOffset(string groupName, MessageQueue messageQueue)
 {
 }
Пример #13
0
        private long ComputePullFromWhere(MessageQueue messageQueue)
        {
            var offset = -1L;

            var lastOffset = _offsetStore.ReadOffset(messageQueue, OffsetReadType.ReadFromStore);
            if (lastOffset >= 0)
            {
                offset = lastOffset;
            }
            else if (lastOffset == -1)
            {
                offset = long.MaxValue;
            }

            return offset;
        }
Пример #14
0
 private void PersistRemovedMessageQueueOffset(MessageQueue messageQueue)
 {
     _offsetStore.Persist(messageQueue);
     _offsetStore.RemoveOffset(messageQueue);
 }
Пример #15
0
        public IList<MessageQueue> GetTopicMessageQueues(string topic)
        {
            IList<MessageQueue> messageQueueList;
            if (_topicMessageQueueDict.TryGetValue(topic, out messageQueueList))
            {
                return messageQueueList;
            }

            lock (_lockObj)
            {
                if (_topicMessageQueueDict.TryGetValue(topic, out messageQueueList))
                {
                    return messageQueueList;
                }
                try
                {
                    var topicRouteInfoList = GetTopicRouteInfoList(topic);
                    messageQueueList = new List<MessageQueue>();

                    foreach (var topicRouteInfo in topicRouteInfoList)
                    {
                        foreach (var queueId in topicRouteInfo.QueueInfo)
                        {
                            var messageQueue = new MessageQueue(topicRouteInfo.BrokerInfo.BrokerName, topic, queueId);
                            messageQueueList.Add(messageQueue);
                        }
                    }
                    SortMessageQueues(messageQueueList);
                    _topicMessageQueueDict[topic] = messageQueueList;
                }
                catch (Exception ex)
                {
                    _logger.Error(string.Format("GetTopicRouteInfoList has exception, topic: {0}", topic), ex);
                }
                return messageQueueList;
            }
        }
 public void RemoveOffset(MessageQueue messageQueue)
 {
 }
Пример #17
0
 public WrappedMessage(MessageQueue messageQueue, QueueMessage queueMessage, ProcessQueue processQueue)
 {
     MessageQueue = messageQueue;
     QueueMessage = queueMessage;
     ProcessQueue = processQueue;
 }
Пример #18
0
        public void CommitConsumeOffset(MessageQueue messageQueue, long consumeOffset, bool throwIfException = false)
        {
            Ensure.NotNull(messageQueue, "messageQueue");
            Ensure.Nonnegative(consumeOffset, "consumeOffset");

            var brokerConnection = _clientService.GetBrokerConnection(messageQueue.BrokerName);
            if (brokerConnection == null)
            {
                _logger.ErrorFormat("CommitConsumeOffset failed as the target broker connection not found, messageQueue:{0}", messageQueue);
                return;
            }
            var remotingClient = brokerConnection.AdminRemotingClient;

            var request = new UpdateQueueOffsetRequest(_consumer.GroupName, messageQueue, consumeOffset);
            var remotingRequest = new RemotingRequest((int)BrokerRequestCode.UpdateQueueConsumeOffsetRequest, _binarySerializer.Serialize(request));
            var brokerAddress = remotingClient.ServerEndPoint.ToAddress();

            try
            {
                remotingClient.InvokeOneway(remotingRequest);
                if (_logger.IsDebugEnabled)
                {
                    _logger.DebugFormat("CommitConsumeOffset success, consumerGroup:{0}, consumerId:{1}, messageQueue:{2}, consumeOffset:{3}, brokerAddress:{4}",
                        _consumer.GroupName,
                        _clientId,
                        messageQueue,
                        consumeOffset,
                        brokerAddress);
                }
            }
            catch (Exception ex)
            {
                if (remotingClient.IsConnected)
                {
                    _logger.Error(string.Format("CommitConsumeOffset has exception, consumerGroup:{0}, consumerId:{1}, messageQueue:{2}, consumeOffset:{3}, brokerAddress:{4}",
                        _consumer.GroupName,
                        _clientId,
                        messageQueue,
                        consumeOffset,
                        brokerAddress), ex);
                }
                if (throwIfException)
                {
                    throw;
                }
            }
        }
Пример #19
0
 public UpdateQueueOffsetRequest(string consumerGroup, MessageQueue messageQueue, long queueOffset)
 {
     ConsumerGroup = consumerGroup;
     MessageQueue = messageQueue;
     QueueOffset = queueOffset;
 }
 public void UpdateOffset(MessageQueue messageQueue, long offset)
 {
 }
Пример #21
0
 public UpdateQueueOffsetRequest(string consumerGroup, MessageQueue messageQueue, long queueOffset)
 {
     ConsumerGroup = consumerGroup;
     MessageQueue  = messageQueue;
     QueueOffset   = queueOffset;
 }