/// <summary>
        /// Enable the Dafda outbox producer implementation, configurable using the <paramref name="options"/>
        /// </summary>
        /// <param name="services">The service collection</param>
        /// <param name="options">Configure the <see cref="OutboxProducerOptions"/></param>
        public static void AddOutboxProducer(this IServiceCollection services, Action <OutboxProducerOptions> options)
        {
            var builder = new ProducerConfigurationBuilder();
            var outboxProducerOptions = new OutboxProducerOptions(builder, services);

            options?.Invoke(outboxProducerOptions);
            var configuration = builder.Build();

            var outboxListener = outboxProducerOptions.OutboxListener;

            if (outboxListener == null)
            {
                throw new InvalidConfigurationException($"No {nameof(IOutboxListener)} was registered. Please use the {nameof(OutboxProducerOptions.WithListener)} in the {nameof(AddOutboxProducer)} configuration.");
            }

            services.AddTransient <IHostedService, OutboxDispatcherHostedService>(provider =>
            {
                var outboxUnitOfWorkFactory = provider.GetRequiredService <IOutboxUnitOfWorkFactory>();
                var loggerFactory           = provider.GetRequiredService <ILoggerFactory>();
                var kafkaProducer           = configuration.KafkaProducerFactory(loggerFactory);
                var producer         = new OutboxProducer(kafkaProducer);
                var outboxDispatcher = new OutboxDispatcher(loggerFactory, outboxUnitOfWorkFactory, producer);

                return(new OutboxDispatcherHostedService(outboxListener, outboxDispatcher));
            });
        }
Esempio n. 2
0
        internal ProducerConfiguration Build()
        {
            var realBuilder = new Dafda.Configuration.ProducerConfigurationBuilder();

            realBuilder.WithBootstrapServers("dummy");

            if (_kafkaProducerFactory != null)
            {
                realBuilder.WithKafkaProducerFactory(_kafkaProducerFactory);
            }

            return(realBuilder.Build());
        }
        private static IProducerConfiguration ConfigureProducerConfiguration(IServiceCollection services, Action <IProducerOptions> options)
        {
            var outgoingMessageRegistry = new OutgoingMessageRegistry();
            var configurationBuilder    = new ProducerConfigurationBuilder();

            configurationBuilder.WithOutgoingMessageRegistry(outgoingMessageRegistry);
            var consumerOptions = new ProducerOptions(configurationBuilder, services, outgoingMessageRegistry);

            options?.Invoke(consumerOptions);
            var producerConfiguration = configurationBuilder.Build();

            return(producerConfiguration);
        }
        private static ProducerFactory CreateProducerFactory <TImplementation>(IServiceCollection services, Action <ProducerOptions> options)
        {
            var outgoingMessageRegistry = new OutgoingMessageRegistry();
            var configurationBuilder    = new ProducerConfigurationBuilder();
            var consumerOptions         = new ProducerOptions(configurationBuilder, outgoingMessageRegistry);

            options?.Invoke(consumerOptions);

            var producerConfiguration = configurationBuilder.Build();

            var factory = AddOrGetRegisteredProducerFactory(services);

            factory.ConfigureProducerFor <TImplementation>(producerConfiguration, outgoingMessageRegistry);
            return(factory);
        }
Esempio n. 5
0
        public static void AddProducerFor <TClient>(this IServiceCollection services, Action <ProducerOptions> options) where TClient : class
        {
            var outgoingMessageRegistry = new OutgoingMessageRegistry();
            var configurationBuilder    = new ProducerConfigurationBuilder();
            var consumerOptions         = new ProducerOptions(configurationBuilder, outgoingMessageRegistry);

            options?.Invoke(consumerOptions);

            var producerConfiguration = configurationBuilder.Build();

            var factory = AddOrGetRegisteredProducerFactory(services);

            factory.ConfigureProducerFor <TClient>(producerConfiguration, outgoingMessageRegistry);

            services.AddTransient <TClient>(provider =>
            {
                var producer = factory.GetFor <TClient>();
                return(ActivatorUtilities.CreateInstance <TClient>(provider, producer));
            });
        }
        public static void AddOutboxProducer(this IServiceCollection services, Action <OutboxProducerOptions> options)
        {
            var builder = new ProducerConfigurationBuilder();
            var outboxProducerOptions = new OutboxProducerOptions(builder, services);

            options?.Invoke(outboxProducerOptions);
            var configuration = builder.Build();


            services.AddTransient <IHostedService, OutboxDispatcherHostedService>(provider =>
            {
                var outboxUnitOfWorkFactory = provider.GetRequiredService <IOutboxUnitOfWorkFactory>();
                var kafkaProducer           = configuration.KafkaProducerFactory();
                var producer           = new OutboxProducer(kafkaProducer);
                var outboxNotification = provider.GetRequiredService <IOutboxNotification>();

                return(new OutboxDispatcherHostedService(
                           outboxUnitOfWorkFactory,
                           producer,
                           outboxNotification
                           ));
            });
        }
Esempio n. 7
0
 internal ProducerOptions(ProducerConfigurationBuilder builder, OutgoingMessageRegistry outgoingMessageRegistry)
 {
     _builder = builder;
     _outgoingMessageRegistry = outgoingMessageRegistry;
 }
Esempio n. 8
0
 internal OutboxProducerOptions(ProducerConfigurationBuilder builder, IServiceCollection services)
 {
     _services = services;
     _builder  = builder;
 }
Esempio n. 9
0
 public ProducerOptions(ProducerConfigurationBuilder builder, IServiceCollection services, IOutgoingMessageRegistry outgoingMessageRegistry)
 {
     _builder  = builder;
     _services = services;
     _outgoingMessageRegistry = outgoingMessageRegistry;
 }