confluentinc / confluent-kafka-dotnet

Confluent's Apache Kafka .NET client
https://github.com/confluentinc/confluent-kafka-dotnet/wiki
Apache License 2.0
61 stars 861 forks source link

Question about SetLogHandler and SetErrorHandler #2178

Open kfrn opened 8 months ago

kfrn commented 8 months ago

I'm looking for some clarity about these two ConsumerBuilder methods.

Here's the current signature and documentation comment for SetLogHandler():

public ConsumerBuilder<TKey,TValue> SetLogHandler(Action<IConsumer<TKey,TValue>,LogMessage> logHandler)
in class ConsumerBuilder<TKey,TValue>

TKey is Ignore
TValue is string 

Set the handler to call when there is information available to be logged. If not specified, a default callback that writes to stderr will be used. Remarks: By default not many log messages are generated. For more verbose logging, specify one or more debug contexts using the 'Debug' configuration property. Warning: Log handlers are called spontaneously from internal librdkafka threads and the application must not call any Confluent.Kafka APIs from within a log handler or perform any prolonged operations. Exceptions: Any exception thrown by your log handler will be silently ignored.

I'm interested in the part in bold. The first parameter to the callback is IConsumer. So you have access to the consumer within the callback... but you're not supposed to call anything on it/use any of its APIs? I want to check if I'm understanding correctly.

SetErrorHandler():

public ConsumerBuilder<TKey,TValue> SetErrorHandler(Action<IConsumer<TKey,TValue>,Error> errorHandler)
in class ConsumerBuilder<TKey,TValue>

TKey is Ignore
TValue is string 

Set the handler to call on error events e.g. connection failures or all brokers down. Note that the client will try to automatically recover from errors that are not marked as fatal. Non-fatal errors should be interpreted as informational rather than catastrophic. Remarks: Executes as a side-effect of the Consume method (on the same thread). Exceptions: Any exception thrown by your error handler will be silently ignored.

Does the same restriction about not using Confluent.Kafka APIs apply for SetErrorHandler()?

Thank you very much :pray: