-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* FIX: Support handler overrides * Resolve builders within scope * Consolidate builder namespace
- Loading branch information
1 parent
a94e46e
commit d66f125
Showing
11 changed files
with
208 additions
and
158 deletions.
There are no files selected for viewing
67 changes: 0 additions & 67 deletions
67
Confluent.Kafka.DependencyInjection/Builders/ConsumerAdapter.cs
This file was deleted.
Oops, something went wrong.
61 changes: 0 additions & 61 deletions
61
Confluent.Kafka.DependencyInjection/Builders/ProducerAdapter.cs
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...ndencyInjection/Builders/ConfigWrapper.cs → ...endencyInjection/Clients/ConfigWrapper.cs
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
76 changes: 76 additions & 0 deletions
76
Confluent.Kafka.DependencyInjection/Clients/DIConsumerBuilder.cs
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 |
---|---|---|
@@ -0,0 +1,76 @@ | ||
namespace Confluent.Kafka.DependencyInjection.Clients; | ||
|
||
using Confluent.Kafka.DependencyInjection.Handlers; | ||
using Confluent.Kafka.SyncOverAsync; | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
sealed class DIConsumerBuilder<TKey, TValue> : ConsumerBuilder<TKey, TValue> | ||
{ | ||
readonly IEnumerable<IErrorHandler> errorHandlers; | ||
readonly IEnumerable<IStatisticsHandler> statisticsHandlers; | ||
readonly IEnumerable<ILogHandler> logHandlers; | ||
readonly IEnumerable<IPartitionsAssignedHandler> assignHandlers; | ||
readonly IEnumerable<IPartitionsRevokedHandler> revokeHandlers; | ||
readonly IEnumerable<IOffsetsCommittedHandler> commitHandlers; | ||
readonly IDeserializer<TKey>? keyDeserializer; | ||
readonly IDeserializer<TValue>? valueDeserializer; | ||
readonly IAsyncDeserializer<TKey>? asyncKeyDeserializer; | ||
readonly IAsyncDeserializer<TValue>? asyncValueDeserializer; | ||
|
||
public DIConsumerBuilder( | ||
ConfigWrapper config, | ||
IEnumerable<IErrorHandler> errorHandlers, | ||
IEnumerable<IStatisticsHandler> statisticsHandlers, | ||
IEnumerable<ILogHandler> logHandlers, | ||
IEnumerable<IPartitionsAssignedHandler> assignHandlers, | ||
IEnumerable<IPartitionsRevokedHandler> revokeHandlers, | ||
IEnumerable<IOffsetsCommittedHandler> commitHandlers, | ||
IDeserializer<TKey>? keyDeserializer = null, | ||
IDeserializer<TValue>? valueDeserializer = null, | ||
IAsyncDeserializer<TKey>? asyncKeyDeserializer = null, | ||
IAsyncDeserializer<TValue>? asyncValueDeserializer = null) | ||
: base(config.Values) | ||
{ | ||
this.errorHandlers = errorHandlers; | ||
this.statisticsHandlers = statisticsHandlers; | ||
this.logHandlers = logHandlers; | ||
this.assignHandlers = assignHandlers; | ||
this.revokeHandlers = revokeHandlers; | ||
this.commitHandlers = commitHandlers; | ||
this.keyDeserializer = keyDeserializer; | ||
this.valueDeserializer = valueDeserializer; | ||
this.asyncKeyDeserializer = asyncKeyDeserializer; | ||
this.asyncValueDeserializer = asyncValueDeserializer; | ||
} | ||
|
||
public override IConsumer<TKey, TValue> Build() | ||
{ | ||
ErrorHandler ??= errorHandlers.Aggregate(default(Action<IClient, Error>), (x, y) => x + y.OnError); | ||
|
||
StatisticsHandler ??= statisticsHandlers.Aggregate( | ||
default(Action<IClient, string>), | ||
(x, y) => x + y.OnStatistics); | ||
|
||
LogHandler ??= logHandlers.Aggregate(default(Action<IClient, LogMessage>), (x, y) => x + y.OnLog); | ||
|
||
PartitionsAssignedHandler ??= assignHandlers.Aggregate( | ||
default(Func<IClient, IEnumerable<TopicPartition>, IEnumerable<TopicPartitionOffset>>), | ||
(x, y) => x + y.OnPartitionsAssigned); | ||
|
||
PartitionsRevokedHandler ??= revokeHandlers.Aggregate( | ||
default(Func<IClient, IEnumerable<TopicPartitionOffset>, IEnumerable<TopicPartitionOffset>>), | ||
(x, y) => x + y.OnPartitionsRevoked); | ||
|
||
OffsetsCommittedHandler ??= commitHandlers.Aggregate( | ||
default(Action<IClient, CommittedOffsets>), | ||
(x, y) => x + y.OnOffsetsCommitted); | ||
|
||
KeyDeserializer ??= keyDeserializer ?? asyncKeyDeserializer?.AsSyncOverAsync(); | ||
ValueDeserializer ??= valueDeserializer ?? asyncValueDeserializer?.AsSyncOverAsync(); | ||
|
||
return base.Build(); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
Confluent.Kafka.DependencyInjection/Clients/DIProducerBuilder.cs
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
namespace Confluent.Kafka.DependencyInjection.Clients; | ||
|
||
using Confluent.Kafka.DependencyInjection.Handlers; | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
sealed class DIProducerBuilder<TKey, TValue> : ProducerBuilder<TKey, TValue> | ||
{ | ||
readonly IEnumerable<IErrorHandler> errorHandlers; | ||
readonly IEnumerable<IStatisticsHandler> statisticsHandlers; | ||
readonly IEnumerable<ILogHandler> logHandlers; | ||
readonly ISerializer<TKey>? keySerializer; | ||
readonly ISerializer<TValue>? valueSerializer; | ||
readonly IAsyncSerializer<TKey>? asyncKeySerializer; | ||
readonly IAsyncSerializer<TValue>? asyncValueSerializer; | ||
|
||
public DIProducerBuilder( | ||
ConfigWrapper config, | ||
IEnumerable<IErrorHandler> errorHandlers, | ||
IEnumerable<IStatisticsHandler> statisticsHandlers, | ||
IEnumerable<ILogHandler> logHandlers, | ||
ISerializer<TKey>? keySerializer = null, | ||
ISerializer<TValue>? valueSerializer = null, | ||
IAsyncSerializer<TKey>? asyncKeySerializer = null, | ||
IAsyncSerializer<TValue>? asyncValueSerializer = null) | ||
: base(config.Values) | ||
{ | ||
this.errorHandlers = errorHandlers; | ||
this.statisticsHandlers = statisticsHandlers; | ||
this.logHandlers = logHandlers; | ||
this.keySerializer = keySerializer; | ||
this.valueSerializer = valueSerializer; | ||
this.asyncKeySerializer = asyncKeySerializer; | ||
this.asyncValueSerializer = asyncValueSerializer; | ||
} | ||
|
||
public override IProducer<TKey, TValue> Build() | ||
{ | ||
ErrorHandler ??= errorHandlers.Aggregate(default(Action<IClient, Error>), (x, y) => x + y.OnError); | ||
|
||
StatisticsHandler ??= statisticsHandlers.Aggregate( | ||
default(Action<IClient, string>), | ||
(x, y) => x + y.OnStatistics); | ||
|
||
LogHandler ??= logHandlers.Aggregate(default(Action<IClient, LogMessage>), (x, y) => x + y.OnLog); | ||
|
||
// Setting both types of serializers is an error. | ||
if ((KeySerializer ??= keySerializer) == null) | ||
{ | ||
AsyncKeySerializer ??= asyncKeySerializer; | ||
} | ||
|
||
if ((ValueSerializer ??= valueSerializer) == null) | ||
{ | ||
AsyncValueSerializer ??= asyncValueSerializer; | ||
} | ||
|
||
return base.Build(); | ||
} | ||
} |
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
Oops, something went wrong.