是Confluent.Kafka.Producer <tkey,tvalue =“”>。生成异步线程安全吗?

时间:2017-12-25 08:24:36

标签: c# apache-kafka kafka-producer-api confluent-kafka

    //
    // 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是线程安全的或不安全的。

它是线程安全的吗?

1 个答案:

答案 0 :(得分:0)

是的,它是

  

客户端上的所有操作都是线程安全的(除了一些小例外   记录在API中。

AFAIK,C#客户端中还没有这样的方法(或者只有私有/内部方法)

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