Пример #1
0
 internal OutboxQueue(MessageIdGenerator messageIdGenerator, OutgoingMessageRegistry outgoingMessageRegistry, IOutboxEntryRepository repository, IOutboxNotifier outboxNotifier, TopicPayloadSerializerRegistry serializerRegistry)
 {
     _repository               = repository;
     _outboxNotifier           = outboxNotifier;
     _serializerRegistry       = serializerRegistry;
     _payloadDescriptorFactory = new PayloadDescriptorFactory(outgoingMessageRegistry, messageIdGenerator);
 }
        public void Has_expected_outgoing_message_registry()
        {
            var dummy = new OutgoingMessageRegistry();

            var sut = new ProducerConfigurationBuilder();

            sut.WithBootstrapServers("foo");
            sut.WithOutgoingMessageRegistry(dummy);
            var producerConfiguration = sut.Build();

            Assert.Equal(dummy, producerConfiguration.OutgoingMessageRegistry);
        }
Пример #3
0
        public void Test1()
        {
            var sut = new OutgoingMessageRegistry();

            sut.Register <Message>("foo", "bar", @event => @event.Id);

            var domainEvent  = new Message("baz");
            var registration = sut.GetRegistration(domainEvent);

            Assert.Equal("foo", registration.Topic);
            Assert.Equal("bar", registration.Type);
            Assert.Equal("baz", registration.KeySelector(domainEvent));
        }
Пример #4
0
        public void returns_expected_when_getting_by_an_unknown_name()
        {
            var producerConfigurationStub   = new ProducerConfigurationBuilder().Build();
            var outgoingMessageRegistryStub = new OutgoingMessageRegistry();

            var sut = new ProducerFactoryBuilder().Build();

            sut.ConfigureProducer("foo", producerConfigurationStub, outgoingMessageRegistryStub);

            var result = sut.Get("bar");

            Assert.Null(result);
        }
        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);
        }
Пример #6
0
        public void returns_expected_when_getting_by_a_known_name()
        {
            var producerConfigurationStub   = A.ValidProducerConfiguration.Build();
            var outgoingMessageRegistryStub = new OutgoingMessageRegistry();

            var sut = new ProducerFactoryBuilder().Build();

            sut.ConfigureProducer("foo", producerConfigurationStub, outgoingMessageRegistryStub);

            var result = sut.Get("foo", NullLoggerFactory.Instance);

            Assert.IsType <Producer>(result);
            Assert.NotNull(result);
        }
        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);
        }
        /// <summary>
        /// Enable the Dafda outbox collector implementation, configurable using the <paramref name="options"/>
        /// </summary>
        /// <param name="services">The service collection</param>
        /// <param name="options">Configure the <see cref="OutboxOptions"/></param>
        public static void AddOutbox(this IServiceCollection services, Action <OutboxOptions> options)
        {
            var outgoingMessageRegistry = new OutgoingMessageRegistry();

            var outboxOptions = new OutboxOptions(services, outgoingMessageRegistry);

            options?.Invoke(outboxOptions);
            var configuration = outboxOptions.Build();

            services.AddTransient(provider => new OutboxQueue(
                                      configuration.MessageIdGenerator,
                                      outgoingMessageRegistry,
                                      provider.GetRequiredService <IOutboxEntryRepository>(),
                                      configuration.Notifier,
                                      configuration.TopicPayloadSerializerRegistry
                                      ));
        }
Пример #9
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 AddOutbox(this IServiceCollection services, Action <OutboxOptions> options)
        {
            var outgoingMessageRegistry = new OutgoingMessageRegistry();

            var outboxOptions = new OutboxOptions(services, outgoingMessageRegistry);

            options?.Invoke(outboxOptions);
            var configuration = outboxOptions.Build();

            services.AddTransient(provider =>
            {
                var messageIdGenerator      = configuration.MessageIdGenerator;
                var outboxMessageRepository = provider.GetRequiredService <IOutboxMessageRepository>();
                var outboxNotifier          = provider.GetRequiredService <IOutboxNotifier>();

                return(new OutboxQueue(
                           messageIdGenerator,
                           outgoingMessageRegistry,
                           outboxMessageRepository,
                           outboxNotifier
                           ));
            });
        }
Пример #11
0
 internal ProducerOptions(ProducerConfigurationBuilder builder, OutgoingMessageRegistry outgoingMessageRegistry)
 {
     _builder = builder;
     _outgoingMessageRegistry = outgoingMessageRegistry;
 }
Пример #12
0
 internal OutboxOptions(IServiceCollection services, OutgoingMessageRegistry outgoingMessageRegistry)
 {
     _services = services;
     _outgoingMessageRegistry = outgoingMessageRegistry;
 }
Пример #13
0
 public OutboxQueueBuilder With(OutgoingMessageRegistry outgoingMessageRegistry)
 {
     _outgoingMessageRegistry = outgoingMessageRegistry;
     return(this);
 }
Пример #14
0
 public ProducerBuilder With(OutgoingMessageRegistry outgoingMessageRegistry)
 {
     _outgoingMessageRegistry = outgoingMessageRegistry;
     return(this);
 }