public KafkaEventPublisher( IKafkaGatewayFactory kafkaGatewayFactory, IEventSerializer serializaer ) { Producer = kafkaGatewayFactory.CreateProducer(); Serializer = serializaer; }
public KafkaEventPublisherTests() { fixture = new Fixture(); producer = Substitute.For <IProducer <string, string> >(); kafkaGatewayFactory = Substitute.For <IKafkaGatewayFactory>(); kafkaGatewayFactory.CreateProducer().Returns(producer); eventSerializer = Substitute.For <IEventSerializer>(); eventSerializer.Serialize <Event>(Arg.Any <Event>()).Returns("We are the knight who say Ni"); eventPublisher = new KafkaEventPublisher(kafkaGatewayFactory, eventSerializer); }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { using (IServiceScope scope = ServiceScopeFactory.CreateScope()) { IServiceProvider serviceProvider = scope.ServiceProvider; IKafkaGatewayFactory kafkaGatewayFactory = serviceProvider.GetRequiredService <IKafkaGatewayFactory>(); IConsumer <Ignore, string> consumer = kafkaGatewayFactory.CreateConsumer(); IEventSerializer eventSerializer = serviceProvider.GetRequiredService <IEventSerializer>(); IMediator mediator = serviceProvider.GetRequiredService <IMediator>(); EventProcessingLoop loop = new EventProcessingLoop( stoppingToken, consumer, eventSerializer, mediator ); await loop.Run(); consumer.Dispose(); } }