public ProducerConfiguration( ClusterConfiguration cluster, string name, string defaultTopic, Acks?acks, MiddlewareConfiguration middlewareConfiguration, ProducerConfig baseProducerConfig, IReadOnlyList <Action <string> > statisticsHandlers, ProducerCustomFactory customFactory) { this.Cluster = cluster ?? throw new ArgumentNullException(nameof(cluster)); this.Name = name; this.DefaultTopic = defaultTopic; this.Acks = acks; this.MiddlewareConfiguration = middlewareConfiguration; this.BaseProducerConfig = baseProducerConfig; this.StatisticsHandlers = statisticsHandlers; this.CustomFactory = customFactory; }
public void Build_AllCalls_ReturnPassedValues() { // Arrange var clusterConfiguration = this.fixture.Create <ClusterConfiguration>(); var defaultTopic = this.fixture.Create <string>(); var acks = this.fixture.Create <KafkaFlow.Acks>(); const int lingerMs = 50; ProducerCustomFactory customFactory = (producer, resolver) => producer; Action <string> statisticsHandler = s => { }; const int statisticsIntervalMs = 100; var producerConfig = new ProducerConfig(); this.target .DefaultTopic(defaultTopic) .WithAcks(acks) .WithLingerMs(lingerMs) .WithCustomFactory(customFactory) .WithStatisticsHandler(statisticsHandler) .WithStatisticsIntervalMs(statisticsIntervalMs) .WithProducerConfig(producerConfig) .AddMiddlewares(m => m.Add <IMessageMiddleware>()); // Act var configuration = this.target.Build(clusterConfiguration); // Assert configuration.Cluster.Should().Be(clusterConfiguration); configuration.Name.Should().Be(this.name); configuration.DefaultTopic.Should().Be(defaultTopic); configuration.Acks.Should().Be(acks); configuration.BaseProducerConfig.LingerMs.Should().Be(lingerMs); configuration.BaseProducerConfig.StatisticsIntervalMs.Should().Be(statisticsIntervalMs); configuration.StatisticsHandlers.Should().HaveElementAt(0, statisticsHandler); configuration.BaseProducerConfig.Should().BeSameAs(producerConfig); configuration.MiddlewareConfiguration.Factories.Should().HaveCount(1); }
/// <summary> /// Register a custom producer factory to be internally used by the framework /// </summary> /// <param name="builder"></param> /// <param name="decoratorFactory">The factory method</param> /// <returns></returns> public static IProducerConfigurationBuilder WithCustomFactory( this IProducerConfigurationBuilder builder, ProducerCustomFactory decoratorFactory) { return(((ProducerConfigurationBuilder)builder).WithCustomFactory(decoratorFactory)); }
public IProducerConfigurationBuilder WithCustomFactory(ProducerCustomFactory customFactory) { this.customFactory = customFactory; return(this); }