-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add KafkaErrorEvent.Handled to prevent built-in logging [#83]
- Loading branch information
1 parent
47a8660
commit 4f10eff
Showing
4 changed files
with
29 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
|
||
namespace Silverback.Messaging.Broker | ||
{ | ||
// TODO: Test | ||
internal class KafkaEventsHandler | ||
{ | ||
private readonly IServiceProvider _serviceProvider; | ||
|
@@ -96,15 +97,29 @@ public void SetConsumerEventsHandlers( | |
// Ignore errors if not consuming anymore | ||
// (lidrdkafka randomly throws some "brokers are down" | ||
// while disconnecting) | ||
if (!ownerConsumer.IsConsuming) return; | ||
if (!ownerConsumer.IsConsuming) | ||
return; | ||
var kafkaErrorEvent = new KafkaErrorEvent(error); | ||
try | ||
{ | ||
CreateScopeAndPublishEvent(kafkaErrorEvent); | ||
} | ||
catch (Exception ex) | ||
{ | ||
_logger.LogError(ex, "Error in KafkaErrorEvent subscriber."); | ||
} | ||
if (kafkaErrorEvent.Handled) | ||
return; | ||
_logger.Log( | ||
error.IsFatal ? LogLevel.Critical : LogLevel.Error, | ||
"Error in Kafka consumer: {error} (topic(s): {topics})", | ||
error, | ||
ownerConsumer.Endpoint.Names); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
msallin
Collaborator
|
||
CreateScopeAndPublishEvent(new KafkaErrorEvent(error)); | ||
}) | ||
.SetStatisticsHandler((_, statistics) => | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Now that I'm using this, I realize that I want to have the very same log message but with another log level. This is currently not possible because I have no access to "ownerConsumer". Can you set this on the KafkaErrorEvent?