title: Kafka consumer commit thread-safety
body: <p>I am using <a href="https://github.com/confluentinc/confluent-kafka-dotnet" rel="nofollow noreferrer">Confluent.Kafka</a> dotnet client.</p>
  
  <pre><code>namespace Confluent.Kafka
  {
      public class Consumer&lt;TKey, TValue&gt; : IDisposable
      {
           public Task&lt;CommittedOffsets&gt; CommitAsync();
      }
  }
  </code></pre>
  
  <p>As you see, Consumer.CommitAsync is an async method.   Is it safe to call <code>CommitAsync</code> method without waiting its response and then make the next call to <code>Subscribe</code>?</p>
  
  <p>Example code below.</p>
  
  <pre><code>using (var consumer = new Confluent.Kafka.Consumer&lt;MessageKey, byte[]&gt;(config, new MessageKeyDeserializer(), new ByteArrayDeserializer()))
  {
                  consumer.Subscribe(topics);
  
                  while (true)
                  {
                      Message&lt;MessageKey, byte[]&gt; msg;
                      if (consumer.Consume(out msg, TimeSpan.FromSeconds(1)))
                      {
                          // ...
  
                          if( msg.Offset % 100 == 0)
                          {
                              consumer.CommitAsync().ContinueWith((t) =&gt;
                             {
                                 // log t.Exception
                             }, TaskContinuationOptions.OnlyOnFaulted);
                          }
                      }
                  }
  }
  </code></pre>