public KafkaMessageConsumerSweepOffsets(ITestOutputHelper output)
        {
            const string groupId = "Kafka Message Producer Sweep Test";

            _output           = output;
            _producerRegistry = new KafkaProducerRegistryFactory(
                new KafkaMessagingGatewayConfiguration
            {
                Name             = "Kafka Producer Send Test",
                BootStrapServers = new[] { "localhost:9092" }
            },
                new KafkaPublication[] { new KafkaPublication()
                                         {
                                             Topic             = new RoutingKey(_topic),
                                             NumPartitions     = 1,
                                             ReplicationFactor = 1,
                                             //These timeouts support running on a container using the same host as the tests,
                                             //your production values ought to be lower
                                             MessageTimeoutMs = 2000,
                                             RequestTimeoutMs = 2000,
                                             MakeChannels     = OnMissingChannel.Create
                                         } }).Create();

            _consumer = (KafkaMessageConsumer) new KafkaMessageConsumerFactory(
                new KafkaMessagingGatewayConfiguration
            {
                Name             = "Kafka Consumer Test",
                BootStrapServers = new[] { "localhost:9092" }
            })
                        .Create(new KafkaSubscription <MyCommand>(
                                    channelName: new ChannelName(_queueName),
                                    routingKey: new RoutingKey(_topic),
                                    groupId: groupId,
                                    commitBatchSize: 20, //This large commit batch size may never be sent
                                    sweepUncommittedOffsetsIntervalMs: 10000,
                                    numOfPartitions: 1,
                                    replicationFactor: 1,
                                    makeChannels: OnMissingChannel.Create
                                    )
                                );
        }
示例#2
0
        public static void AddEventuateTramKafkaConsumer(this IServiceCollection serviceCollection,
                                                         string eventuateDatabaseSchema, string bootstrapServers,
                                                         EventuateKafkaConsumerConfigurationProperties consumerConfigurationProperties,
                                                         Action <IServiceProvider, DbContextOptionsBuilder> dbContextOptionsAction)
        {
            AddEventuateTramCommonSqlMessagingServices(serviceCollection, eventuateDatabaseSchema, dbContextOptionsAction);
            AddEventuateTramCommonConsumer(serviceCollection);
            serviceCollection.TryAddScoped <IDuplicateMessageDetector, SqlTableBasedDuplicateMessageDetector>();
            serviceCollection.TryAddSingleton(provider =>
            {
                var loggerFactory                  = provider.GetRequiredService <ILoggerFactory>();
                var serviceScopeFactory            = provider.GetRequiredService <IServiceScopeFactory>();
                var decoratedMessageHandlerFactory = provider.GetRequiredService <DecoratedMessageHandlerFactory>();

                IMessageConsumer messageConsumer = new KafkaMessageConsumer(bootstrapServers,
                                                                            consumerConfigurationProperties, decoratedMessageHandlerFactory,
                                                                            loggerFactory, serviceScopeFactory);

                return(messageConsumer);
            });
            serviceCollection.AddHostedService <DomainEventDispatcherInitializer>();
        }