Stop() public method

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
return void
コード例 #1
0
ファイル: ProducerTests.cs プロジェクト: jsifantu/kafka-net
        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...");
            }
        }
コード例 #2
0
ファイル: ProducerTests.cs プロジェクト: jsifantu/kafka-net
 public async void SendingMessageWhenStoppedShouldThrow()
 {
     var router = Substitute.For<IBrokerRouter>();
     using (var producer = new Producer(router))
     {
         producer.Stop(false);
         await producer.SendMessageAsync("Test", new[] { new Message() });
     }
 }