Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added producerOnly param to EnableAdminMessages method #454

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,58 +20,69 @@ public static class ClusterConfigurationBuilderExtensions
/// <param name="topic">The topic to be used by the admin commands</param>
/// <param name="consumerGroup">The consumer group prefix</param>
/// <param name="topicPartition">The partition used to produce and consumer admin messages</param>
/// <param name="producerOnly">To produce admin messages only</param>
/// <returns></returns>
public static IClusterConfigurationBuilder EnableAdminMessages(
this IClusterConfigurationBuilder cluster,
string topic,
string consumerGroup = null,
int topicPartition = 0)
int topicPartition = 0,
bool producerOnly = false)
{
consumerGroup ??= $"Admin-{Assembly.GetEntryAssembly()!.GetName().Name}";

cluster.DependencyConfigurator
.AddSingleton<IAdminProducer>(
resolver => new AdminProducer(
resolver.Resolve<IMessageProducer<AdminProducer>>(),
topicPartition))
.AddSingleton<IConsumerAdmin, ConsumerAdmin>();
topicPartition));

return cluster
cluster
.AddProducer<AdminProducer>(
producer => producer
.DefaultTopic(topic)
.AddMiddlewares(
middlewares => middlewares
.AddSerializer<ProtobufNetSerializer>()))
.AddConsumer(
consumer => consumer
.ManualAssignPartitions(topic, new[] { topicPartition })
.WithGroupId(consumerGroup)
.WithoutStoringOffsets()
.WithWorkersCount(1)
.WithBufferSize(1)
.WithAutoOffsetReset(AutoOffsetReset.Latest)
.DisableManagement()
.AddMiddlewares(
middlewares => middlewares
.AddSerializer<ProtobufNetSerializer>()
.AddTypedHandlers(
handlers => handlers
.WithHandlerLifetime(InstanceLifetime.Singleton)
.AddHandlers(
new[]
{
typeof(ChangeConsumerWorkersCountHandler),
typeof(PauseConsumerByNameHandler),
typeof(PauseConsumersByGroupHandler),
typeof(ResetConsumerOffsetHandler),
typeof(RestartConsumerByNameHandler),
typeof(ResumeConsumerByNameHandler),
typeof(ResumeConsumersByGroupHandler),
typeof(RewindConsumerOffsetToDateTimeHandler),
typeof(StartConsumerByNameHandler),
typeof(StopConsumerByNameHandler),
}))));
.AddSerializer<ProtobufNetSerializer>()));

if (!producerOnly)
{
cluster.DependencyConfigurator
.AddSingleton<IConsumerAdmin, ConsumerAdmin>();

cluster
.AddConsumer(
consumer => consumer
.ManualAssignPartitions(topic, new[] { topicPartition })
.WithGroupId(consumerGroup)
.WithoutStoringOffsets()
.WithWorkersCount(1)
.WithBufferSize(1)
.WithAutoOffsetReset(AutoOffsetReset.Latest)
.DisableManagement()
.AddMiddlewares(
middlewares => middlewares
.AddSerializer<ProtobufNetSerializer>()
.AddTypedHandlers(
handlers => handlers
.WithHandlerLifetime(InstanceLifetime.Singleton)
.AddHandlers(
new[]
{
typeof(ChangeConsumerWorkersCountHandler),
typeof(PauseConsumerByNameHandler),
typeof(PauseConsumersByGroupHandler),
typeof(ResetConsumerOffsetHandler),
typeof(RestartConsumerByNameHandler),
typeof(ResumeConsumerByNameHandler),
typeof(ResumeConsumersByGroupHandler),
typeof(RewindConsumerOffsetToDateTimeHandler),
typeof(StartConsumerByNameHandler),
typeof(StopConsumerByNameHandler),
}))));
}

return cluster;
}

/// <summary>
Expand Down