コード例 #1
0
 protected override void DoBeforeConsuming(ConsumerLeaseKey key, long correlationId)
 {
     ISchedulePolicy noEndpointSchedulePolicy = new ExponentialSchedulePolicy(Config.NoEndpointWaitBaseMillis, Config.NoEndpointWaitMaxMillis);
     pullMessagesTask.WriteFullFence(new DefaultPullMessagesTask(correlationId, noEndpointSchedulePolicy, this));
 }
コード例 #2
0
        private void StartConsuming(ConsumerLeaseKey key, long correlationId)
        {
            ConsumerNotifier.Register(correlationId, Context);
            DoBeforeConsuming(key, correlationId);
            msgs.Clear();
            ISchedulePolicy noMessageSchedulePolicy = new ExponentialSchedulePolicy(Config.NoMessageWaitBaseMillis, Config.NoMessageWaitMaxMillis);

            while (!IsClosed() && !leaseRef.ReadFullFence().Expired)
            {

                try
                {
                    // if leaseRemainingTime < stopConsumerTimeMillsBeforLeaseExpired, stop
                    if (leaseRef.ReadFullFence().RemainingTime <= Config.StopConsumerTimeMillsBeforLeaseExpired)
                    {
                        break;
                    }

                    if (msgs.Count == 0)
                    {
                        SchedulePullMessagesTask();
                    }

                    if (msgs.Count != 0)
                    {
                        ConsumeMessages(correlationId);
                        noMessageSchedulePolicy.Succeess();
                    }
                    else
                    {
                        noMessageSchedulePolicy.Fail(true);
                    }

                }
                catch (Exception e)
                {
                    log.Error(string.Format("Exception occurred while consuming message(topic={0}, partition={1}, groupId={2}, sessionId={3})",
                            Context.Topic.Name, PartitionId, Context.GroupId, Context.SessionId), e);
                }
            }

            ConsumerNotifier.Deregister(correlationId);
            leaseRef.WriteFullFence(null);
            DoAfterConsuming(key, correlationId);
        }