Confluent.Kafka.Producer<TKey, TValue>.ProduceAsync 线程安全吗?

Is Confluent.Kafka.Producer<TKey, TValue>.ProduceAsync thread-safe?

    //
    // Summary:
    //     Asynchronously send a single message to the broker. Refer to Confluent.Kafka.Producer`2.ProduceAsync(System.String,`0,`1,System.Int32,System.Boolean)
    //     for more information.
    //
    // Remarks:
    //     The partition the message is produced to is determined using the configured partitioner.
    //     Blocks if the send queue is full. Warning: if background polling is disabled
    //     and Poll is not being called in another thread, this will block indefinitely.
    public Task<Message<TKey, TValue>> ProduceAsync(string topic, TKey key, TValue val);
    //
    // Summary:
    //     Asynchronously send a single message to the broker.
    //
    // Parameters:
    //   topic:
    //     The target topic.
    //
    //   partition:
    //     The target partition (if -1, this is determined by the partitioner configured
    //     for the topic).
    //
    //   key:
    //     the message key (possibly null if allowed by the key serializer).
    //
    //   val:
    //     the message value (possibly null if allowed by the value serializer).
    //
    //   blockIfQueueFull:
    //     Whether or not to block if the send queue is full. If false, a KafkaExcepion
    //     (with Error.Code == ErrorCode.Local_QueueFull) will be thrown if an attempt is
    //     made to produce a message and the send queue is full. Warning: blockIfQueueFull
    //     is set to true, background polling is disabled and Poll is not being called in
    //     another thread, this will block indefinitely.
    //
    // Returns:
    //     A Task which will complete with the corresponding delivery report for this request.
    //
    // Remarks:
    //     If you require strict ordering of delivery reports to be maintained, you should
    //     use a variant of ProduceAsync that takes an IDeliveryHandler parameter, not a
    //     variant that returns a Task<Message> because Tasks are completed on arbitrary
    //     thread pool threads and can be executed out of order.
    public Task<Message<TKey, TValue>> ProduceAsync(string topic, TKey key, TValue val, int partition, bool blockIfQueueFull);
    //
    // Summary:
    //     Asynchronously send a single message to the broker. Refer to Confluent.Kafka.Producer`2.ProduceAsync(System.String,`0,`1,System.Int32,System.Boolean)
    //     for more information.
    //
    // Remarks:
    //     Blocks if the send queue is full. Warning: if background polling is disabled
    //     and Poll is not being called in another thread, this will block indefinitely.
    public Task<Message<TKey, TValue>> ProduceAsync(string topic, TKey key, TValue val, int partition);
    //
    // Summary:
    //     Asynchronously send a single message to the broker. Refer to Confluent.Kafka.Producer`2.ProduceAsync(System.String,`0,`1,System.Int32,System.Boolean)
    //     for more information.
    //
    // Remarks:
    //     The partition the message is produced to is determined using the configured partitioner.
    public Task<Message<TKey, TValue>> ProduceAsync(string topic, TKey key, TValue val, bool blockIfQueueFull);

document 没有说明 ProduceAsync 是线程安全的还是不安全的。

它是线程安全的吗?

是的,是

All operation on client are thread safe (with some small exceptions documented in the API).

据我所知,C# 客户端中还没有这样的方法(或者只有 private/internal 方法)

https://github.com/confluentinc/confluent-kafka-dotnet/wiki/Client-Creation https://github.com/edenhill/librdkafka/wiki/FAQ#is-the-library-thread-safe