KafkaNet.Producer.Stop C# (CSharp) 메소드

Stop() 공개 메소드

Stops the producer from accepting new messages, and optionally waits for in-flight messages to be sent before returning.
public Stop ( bool waitForRequestsToComplete = true, System.TimeSpan maxWait = null ) : void
waitForRequestsToComplete bool True to wait for in-flight requests to complete, false otherwise.
maxWait System.TimeSpan Maximum time to wait for in-flight requests to complete. Has no effect if waitForRequestsToComplete is false
리턴 void
        public void Stop(bool waitForRequestsToComplete = true, TimeSpan? maxWait = null)
        {
            //block incoming data
            _asyncCollection.CompleteAdding();

            if (waitForRequestsToComplete)
            {
                //wait for the collection to drain
                _postTask.Wait(maxWait ?? TimeSpan.FromSeconds(MaxDisposeWaitSeconds));
            }

            _stopToken.Cancel();
        }

Usage Example

예제 #1
0
        public async void StopShouldWaitUntilCollectionEmpty()
        {
            var fakeRouter = new FakeBrokerRouter();

            using (var producer = new Producer(fakeRouter.Create()) { BatchDelayTime = TimeSpan.FromMilliseconds(500) })
            {
                var sendTask = producer.SendMessageAsync(FakeBrokerRouter.TestTopic, new[] { new Message() });
                Assert.That(producer.BufferCount, Is.EqualTo(1));

                producer.Stop(true, TimeSpan.FromSeconds(5));

                await sendTask;
                Assert.That(producer.BufferCount, Is.EqualTo(0));
                Assert.That(sendTask.IsCompleted, Is.True);

                Console.WriteLine("Unwinding test...");
            }
        }
All Usage Examples Of KafkaNet.Producer::Stop