Exemple #1
0
        private void PersistOffset(PullRequest pullRequest)
        {
            try
            {
                var consumedQueueOffset = pullRequest.ProcessQueue.GetConsumedQueueOffset();
                if (consumedQueueOffset >= 0)
                {
                    if (!pullRequest.ProcessQueue.TryUpdatePreviousConsumedQueueOffset(consumedQueueOffset))
                    {
                        return;
                    }

                    var request         = new UpdateQueueOffsetRequest(GroupName, pullRequest.MessageQueue, consumedQueueOffset);
                    var remotingRequest = new RemotingRequest((int)RequestCode.UpdateQueueOffsetRequest, _binarySerializer.Serialize(request));
                    _remotingClient.InvokeOneway(remotingRequest);
                    _logger.DebugFormat("Sent queue consume offset to broker. group:{0}, consumerId:{1}, topic:{2}, queueId:{3}, offset:{4}",
                                        GroupName,
                                        Id,
                                        pullRequest.MessageQueue.Topic,
                                        pullRequest.MessageQueue.QueueId,
                                        consumedQueueOffset);
                }
            }
            catch (Exception ex)
            {
                if (_remotingClient.IsConnected)
                {
                    _logger.Error(string.Format("PersistOffset has exception, consumerId:{0}, group:{1}, topic:{2}, queueId:{3}", Id, GroupName, pullRequest.MessageQueue.Topic, pullRequest.MessageQueue.QueueId), ex);
                }
            }
        }
        private void ResetNextConsumeOffset(PullRequest pullRequest, long newOffset)
        {
            var brokerConnection = _clientService.GetBrokerConnection(pullRequest.MessageQueue.BrokerName);

            if (brokerConnection == null)
            {
                _logger.ErrorFormat("Reset nextConsumeOffset failed as broker is unavailable, pullRequest: {0}, newOffset: {1}", pullRequest, newOffset);
                return;
            }
            var remotingClient = brokerConnection.AdminRemotingClient;

            try
            {
                var oldOffset = pullRequest.NextConsumeOffset;
                pullRequest.NextConsumeOffset = newOffset;
                pullRequest.ProcessQueue.MarkAllConsumingMessageIgnored();
                pullRequest.ProcessQueue.Reset();

                var request         = new UpdateQueueOffsetRequest(_consumer.GroupName, pullRequest.MessageQueue, newOffset - 1);
                var remotingRequest = new RemotingRequest((int)BrokerRequestCode.UpdateQueueConsumeOffsetRequest, _binarySerializer.Serialize(request));
                remotingClient.InvokeOneway(remotingRequest);
                _logger.InfoFormat("Resetted nextConsumeOffset, [pullRequest:{0}, oldOffset:{1}, newOffset:{2}]", pullRequest, oldOffset, newOffset);
            }
            catch (Exception ex)
            {
                if (remotingClient.IsConnected)
                {
                    _logger.Error(string.Format("Reset nextConsumeOffset failed, pullRequest: {0}, newOffset: {1}", pullRequest, newOffset), ex);
                }
            }
        }
Exemple #3
0
 public void CommitConsumeOffset(string topic, int queueId, long consumeOffset)
 {
     if (consumeOffset < 0)
     {
         throw new ArgumentOutOfRangeException("Invalid consumeOffset: " + consumeOffset);
     }
     try
     {
         var messageQueue    = new MessageQueue(topic, queueId);
         var request         = new UpdateQueueOffsetRequest(GroupName, messageQueue, consumeOffset);
         var remotingRequest = new RemotingRequest((int)RequestCode.UpdateQueueOffsetRequest, _binarySerializer.Serialize(request));
         _adminRemotingClient.InvokeOneway(remotingRequest);
         if (_logger.IsDebugEnabled)
         {
             _logger.DebugFormat("Sent consumeOffset to broker, [group:{0}, topic:{1}, queueId:{2}, offset:{3}]",
                                 GroupName,
                                 messageQueue.Topic,
                                 messageQueue.QueueId,
                                 consumeOffset);
         }
     }
     catch (Exception ex)
     {
         if (_adminRemotingClient.IsConnected)
         {
             _logger.Error(string.Format("Send consumeOffset to broker has exception, [group:{0}, topic:{1}, queueId:{2}]", GroupName, topic, queueId), ex);
         }
     }
 }
Exemple #4
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;
                }
            }
        }
Exemple #5
0
        private void ResetNextConsumeOffset(PullRequest pullRequest, long newOffset)
        {
            try
            {
                var oldOffset = pullRequest.NextConsumeOffset;
                pullRequest.NextConsumeOffset = newOffset;
                pullRequest.ProcessQueue.MarkAllConsumingMessageIgnored();
                pullRequest.ProcessQueue.Reset();

                var request         = new UpdateQueueOffsetRequest(GroupName, pullRequest.MessageQueue, newOffset - 1);
                var remotingRequest = new RemotingRequest((int)RequestCode.UpdateQueueOffsetRequest, _binarySerializer.Serialize(request));
                _adminRemotingClient.InvokeOneway(remotingRequest);

                _logger.InfoFormat("Reset queue next consume offset, [topic:{0}, queueId:{1}, oldOffset:{2}, newOffset:{3}]", pullRequest.MessageQueue.Topic, pullRequest.MessageQueue.QueueId, oldOffset, newOffset);
            }
            catch (Exception ex)
            {
                if (_adminRemotingClient.IsConnected)
                {
                    _logger.Error(string.Format("ResetNextConsumeOffset has exception, pullRequest: {0}, newOffset: {1}", pullRequest, newOffset), ex);
                }
            }
        }
        private void ResetNextConsumeOffset(PullRequest pullRequest, long newOffset)
        {
            var brokerConnection = _clientService.GetBrokerConnection(pullRequest.MessageQueue.BrokerName);
            if (brokerConnection == null)
            {
                _logger.ErrorFormat("Reset nextConsumeOffset failed as broker is unavailable, pullRequest: {0}, newOffset: {1}", pullRequest, newOffset);
                return;
            }
            var remotingClient = brokerConnection.AdminRemotingClient;

            try
            {
                var oldOffset = pullRequest.NextConsumeOffset;
                pullRequest.NextConsumeOffset = newOffset;
                pullRequest.ProcessQueue.MarkAllConsumingMessageIgnored();
                pullRequest.ProcessQueue.Reset();

                var request = new UpdateQueueOffsetRequest(_consumer.GroupName, pullRequest.MessageQueue, newOffset - 1);
                var remotingRequest = new RemotingRequest((int)BrokerRequestCode.UpdateQueueConsumeOffsetRequest, _binarySerializer.Serialize(request));
                remotingClient.InvokeOneway(remotingRequest);
                _logger.InfoFormat("Resetted nextConsumeOffset, [pullRequest:{0}, oldOffset:{1}, newOffset:{2}]", pullRequest, oldOffset, newOffset);
            }
            catch (Exception ex)
            {
                if (remotingClient.IsConnected)
                {
                    _logger.Error(string.Format("Reset nextConsumeOffset failed, pullRequest: {0}, newOffset: {1}", pullRequest, newOffset), ex);
                }
            }
        }
        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;
                }
            }
        }