/// <summary>
        ///     <para>
        ///         Adds the necessary services to enable the <see cref="OutboxProduceStrategy" />.
        ///     </para>
        ///     <para>
        ///         The <see cref="OutboxProduceStrategy" /> stores the outbound messages into an intermediate outbox,
        ///         participating in the database transaction. The outbound messages become therefore transactional
        ///         with the side effects on the local database.
        ///     </para>
        /// </summary>
        /// <typeparam name="TOutbox">
        ///     The type implementing both the <see cref="IOutboxWriter" /> and the <see cref="IOutboxReader" />
        ///     interfaces.
        /// </typeparam>
        /// <param name="brokerOptionsBuilder">
        ///     The <see cref="IBrokerOptionsBuilder" /> that references the <see cref="IServiceCollection" /> to
        ///     add the services to.
        /// </param>
        /// <returns>
        ///     The <see cref="IBrokerOptionsBuilder" /> so that additional calls can be chained.
        /// </returns>
        public static IBrokerOptionsBuilder AddOutbox <TOutbox>(this IBrokerOptionsBuilder brokerOptionsBuilder)
            where TOutbox : class, IOutboxWriter, IOutboxReader
        {
            Check.NotNull(brokerOptionsBuilder, nameof(brokerOptionsBuilder));

            return(brokerOptionsBuilder.AddOutbox <TOutbox, TOutbox>());
        }
示例#2
0
        /// <summary>
        ///     Adds an <see cref="OutboxWorker" /> to publish the messages stored in the outbox to the configured
        ///     broker.
        /// </summary>
        /// <param name="brokerOptionsBuilder">
        ///     The <see cref="IBrokerOptionsBuilder" /> that references the <see cref="IServiceCollection" /> to
        ///     add the services to.
        /// </param>
        /// <param name="interval">
        ///     The interval between each run. The default is 500ms.
        /// </param>
        /// <param name="enforceMessageOrder">
        ///     If set to <c>true</c> the message order will be ensured, retrying the same message until it can be
        ///     successfully
        ///     produced.
        /// </param>
        /// <param name="readBatchSize">
        ///     The number of messages to be loaded from the queue at once.
        /// </param>
        /// <param name="distributedLockSettings">
        ///     The settings for the locking mechanism. The default settings will be used if not specified.
        /// </param>
        /// <returns>
        ///     The <see cref="IBrokerOptionsBuilder" /> so that additional calls can be chained.
        /// </returns>
        public static IBrokerOptionsBuilder AddOutboxWorker(
            this IBrokerOptionsBuilder brokerOptionsBuilder,
            TimeSpan?interval        = null,
            bool enforceMessageOrder = true,
            int readBatchSize        = 100,
            DistributedLockSettings?distributedLockSettings = null)
        {
            Check.NotNull(brokerOptionsBuilder, nameof(brokerOptionsBuilder));

            distributedLockSettings ??= new DistributedLockSettings();
            distributedLockSettings.EnsureResourceNameIsSet("OutboxWorker");

            brokerOptionsBuilder.SilverbackBuilder.Services
            .AddSingleton <IOutboxWorker>(
                serviceProvider => new OutboxWorker(
                    serviceProvider.GetRequiredService <IServiceScopeFactory>(),
                    serviceProvider.GetRequiredService <IBrokerCollection>(),
                    serviceProvider.GetRequiredService <IOutboundRoutingConfiguration>(),
                    serviceProvider.GetRequiredService <ISilverbackIntegrationLogger <OutboxWorker> >(),
                    enforceMessageOrder,
                    readBatchSize))
            .AddSingleton <IHostedService>(
                serviceProvider => new OutboxWorkerService(
                    interval ?? TimeSpan.FromMilliseconds(500),
                    serviceProvider.GetRequiredService <IOutboxWorker>(),
                    distributedLockSettings,
                    serviceProvider.GetService <IDistributedLockManager>() ?? new NullLockManager(),
                    serviceProvider.GetRequiredService <ISilverbackLogger <OutboxWorkerService> >()));

            return(brokerOptionsBuilder);
        }
示例#3
0
        /// <summary>
        ///     Specifies the <see cref="BrokerConnectionOptions"/>.
        /// </summary>
        /// <param name="brokerOptionsBuilder">
        ///     The <see cref="IBrokerOptionsBuilder" /> that references the <see cref="IServiceCollection" /> to
        ///     add the services to.
        /// </param>
        /// <param name="connectionOptions">
        /// The <see cref="BrokerConnectionOptions"/> to apply.
        /// </param>
        /// <returns>
        ///     The <see cref="IBrokerOptionsBuilder" /> so that additional calls can be chained.
        /// </returns>
        public static IBrokerOptionsBuilder WithConnectionOptions(this IBrokerOptionsBuilder brokerOptionsBuilder, BrokerConnectionOptions connectionOptions)
        {
            Check.NotNull(brokerOptionsBuilder, nameof(brokerOptionsBuilder));

            brokerOptionsBuilder.SilverbackBuilder.Services.AddSingleton(connectionOptions);

            return(brokerOptionsBuilder);
        }
        /// <inheritdoc cref="IBrokerOptionsConfigurator{TBroker}.Configure" />
        public void Configure(IBrokerOptionsBuilder brokerOptionsBuilder)
        {
            Check.NotNull(brokerOptionsBuilder, nameof(brokerOptionsBuilder));

            brokerOptionsBuilder.SilverbackBuilder
            .AddSingletonBrokerBehavior <RabbitRoutingKeyInitializerProducerBehavior>()
            .Services
            .AddSingleton <IRabbitConnectionFactory, RabbitConnectionFactory>();
        }
        /// <summary>
        ///     Registers Apache Kafka as message broker but replaces the Kafka connectivity based on Confluent.Kafka
        ///     with a mocked in-memory message broker that <b>more or less</b> replicates the Kafka behavior.
        /// </summary>
        /// <param name="brokerOptionsBuilder">
        ///     The <see cref="IBrokerOptionsBuilder" /> that references the <see cref="IServiceCollection" /> to
        ///     add the services to.
        /// </param>
        /// <param name="optionsAction">
        ///     Additional options (such as topics and partitions settings).
        /// </param>
        /// <returns>
        ///     The <see cref="IBrokerOptionsBuilder" /> so that additional calls can be chained.
        /// </returns>
        public static IBrokerOptionsBuilder AddMockedKafka(this IBrokerOptionsBuilder brokerOptionsBuilder, Action <IMockedKafkaOptionsBuilder>?optionsAction = null)
        {
            Check.NotNull(brokerOptionsBuilder, nameof(brokerOptionsBuilder));

            brokerOptionsBuilder.AddKafka();
            brokerOptionsBuilder.SilverbackBuilder.Services.UseMockedKafka(optionsAction);

            return(brokerOptionsBuilder);
        }
        /// <summary>
        ///     Registers Apache Mqtt as message broker but replaces the MQTT connectivity based on MQTTnet
        ///     with a mocked in-memory message broker that <b>more or less</b> replicates the MQTT broker behavior.
        /// </summary>
        /// <param name="brokerOptionsBuilder">
        ///     The <see cref="IBrokerOptionsBuilder" /> that references the <see cref="IServiceCollection" /> to
        ///     add the services to.
        /// </param>
        /// <returns>
        ///     The <see cref="IBrokerOptionsBuilder" /> so that additional calls can be chained.
        /// </returns>
        public static IBrokerOptionsBuilder AddMockedMqtt(this IBrokerOptionsBuilder brokerOptionsBuilder)
        {
            Check.NotNull(brokerOptionsBuilder, nameof(brokerOptionsBuilder));

            brokerOptionsBuilder.AddMqtt();
            brokerOptionsBuilder.SilverbackBuilder.UseMockedMqtt();

            return(brokerOptionsBuilder);
        }
        /// <inheritdoc cref="IBrokerOptionsConfigurator{TBroker}.Configure" />
        public void Configure(IBrokerOptionsBuilder brokerOptionsBuilder)
        {
            Check.NotNull(brokerOptionsBuilder, nameof(brokerOptionsBuilder));

            brokerOptionsBuilder.SilverbackBuilder
            .Services
            .AddSingleton <IMqttClientsCache, MqttClientsCache>()
            .AddSingleton <IMqttNetClientFactory, MqttNetClientFactory>();
        }
示例#8
0
        /// <summary>
        ///     <para>
        ///         Adds the necessary services to enable the <see cref="LogExactlyOnceStrategy" />.
        ///     </para>
        ///     <para>
        ///         The <see cref="LogExactlyOnceStrategy" /> stores uses an <see cref="IInboundLog" /> to
        ///         keep track of to keep track of each processed message and guarantee that each one is processed
        ///         only once.
        ///     </para>
        /// </summary>
        /// <typeparam name="TInboundLog">
        ///     The type of the <see cref="IInboundLog" /> to be used.
        /// </typeparam>
        /// <param name="brokerOptionsBuilder">
        ///     The <see cref="IBrokerOptionsBuilder" /> that references the <see cref="IServiceCollection" /> to
        ///     add the services to.
        /// </param>
        /// <returns>
        ///     The <see cref="IBrokerOptionsBuilder" /> so that additional calls can be chained.
        /// </returns>
        public static IBrokerOptionsBuilder AddInboundLog <TInboundLog>(this IBrokerOptionsBuilder brokerOptionsBuilder)
            where TInboundLog : class, IInboundLog
        {
            Check.NotNull(brokerOptionsBuilder, nameof(brokerOptionsBuilder));

            brokerOptionsBuilder.SilverbackBuilder.Services
            .AddScoped <IInboundLog, TInboundLog>();

            return(brokerOptionsBuilder);
        }
        /// <summary>
        ///     <para>
        ///         Adds the necessary services to enable the <see cref="OffsetStoreExactlyOnceStrategy" />.
        ///     </para>
        ///     <para>
        ///         The <see cref="OffsetStoreExactlyOnceStrategy" /> stores uses an <see cref="IOffsetStore" /> to
        ///         keep track of the latest processed offsets and guarantee that each message is processed only once.
        ///     </para>
        /// </summary>
        /// <typeparam name="TOffsetStore">
        ///     The type of the <see cref="IOffsetStore" /> to be used.
        /// </typeparam>
        /// <param name="brokerOptionsBuilder">
        ///     The <see cref="IBrokerOptionsBuilder" /> that references the <see cref="IServiceCollection" /> to
        ///     add the services to.
        /// </param>
        /// <returns>
        ///     The <see cref="IBrokerOptionsBuilder" /> so that additional calls can be chained.
        /// </returns>
        public static IBrokerOptionsBuilder AddOffsetStore <TOffsetStore>(
            this IBrokerOptionsBuilder brokerOptionsBuilder)
            where TOffsetStore : class, IOffsetStore
        {
            Check.NotNull(brokerOptionsBuilder, nameof(brokerOptionsBuilder));

            brokerOptionsBuilder.SilverbackBuilder.Services
            .AddScoped <IOffsetStore, TOffsetStore>();

            return(brokerOptionsBuilder);
        }
        /// <summary>
        ///     Enables registration of duplicate endpoints.
        /// </summary>
        /// <param name="brokerOptionsBuilder">
        ///     The <see cref="IBrokerOptionsBuilder"/>.
        /// </param>
        /// <returns>
        ///     The <see cref="IBrokerOptionsBuilder"/> so that additional calls can be chained.
        /// </returns>
        public static IBrokerOptionsBuilder AllowDuplicateEndpointRegistrations(this IBrokerOptionsBuilder brokerOptionsBuilder)
        {
            Check.NotNull(brokerOptionsBuilder, nameof(brokerOptionsBuilder));

            var outboundRoutingConfiguration =
                brokerOptionsBuilder.SilverbackBuilder.Services.GetSingletonServiceInstance <IOutboundRoutingConfiguration>() ??
                throw new InvalidOperationException(
                          "IOutboundRoutingConfiguration not found, " +
                          "WithConnectionToMessageBroker has not been called.");

            outboundRoutingConfiguration.IdempotentEndpointRegistration = false;

            return(brokerOptionsBuilder);
        }
        /// <inheritdoc cref="IBrokerOptionsConfigurator{TBroker}.Configure" />
        public void Configure(IBrokerOptionsBuilder brokerOptionsBuilder)
        {
            Check.NotNull(brokerOptionsBuilder, nameof(brokerOptionsBuilder));

            brokerOptionsBuilder.SilverbackBuilder
            .AddSingletonBrokerBehavior <RabbitRoutingKeyInitializerProducerBehavior>()
            .Services
            .AddSingleton <IRabbitConnectionFactory, RabbitConnectionFactory>();

            brokerOptionsBuilder.LogTemplates
            .ConfigureAdditionalData <RabbitQueueConsumerEndpoint>("deliveryTag")
            .ConfigureAdditionalData <RabbitExchangeConsumerEndpoint>("deliveryTag", "routingKey")
            .ConfigureAdditionalData <RabbitExchangeProducerEndpoint>("routingKey");
        }
        /// <inheritdoc cref="IBrokerOptionsConfigurator{TBroker}.Configure" />
        public void Configure(IBrokerOptionsBuilder brokerOptionsBuilder)
        {
            Check.NotNull(brokerOptionsBuilder, nameof(brokerOptionsBuilder));

            brokerOptionsBuilder.SilverbackBuilder
            .AddSingletonBrokerBehavior <KafkaMessageKeyInitializerProducerBehavior>()
            .Services
            .AddTransient <IConfluentProducerBuilder, ConfluentProducerBuilder>()
            .AddTransient <IConfluentConsumerBuilder, ConfluentConsumerBuilder>();

            brokerOptionsBuilder.LogTemplates
            .ConfigureAdditionalData <KafkaConsumerEndpoint>("offset", "kafkaKey")
            .ConfigureAdditionalData <KafkaProducerEndpoint>("offset", "kafkaKey");
        }
        /// <summary>
        ///     <para>
        ///         Adds the necessary services to enable the <see cref="OutboxProduceStrategy" />.
        ///     </para>
        ///     <para>
        ///         The <see cref="OutboxProduceStrategy" /> stores the outbound messages into an intermediate outbox,
        ///         participating in the database transaction. The outbound messages become therefore transactional
        ///         with the side effects on the local database.
        ///     </para>
        /// </summary>
        /// <typeparam name="TOutboxWriter">
        ///     The type of the <see cref="IOutboxWriter" /> to be used.
        /// </typeparam>
        /// <typeparam name="TOutboxReader">
        ///     The type of the <see cref="IOutboxReader" /> to be used.
        /// </typeparam>
        /// <param name="brokerOptionsBuilder">
        ///     The <see cref="IBrokerOptionsBuilder" /> that references the <see cref="IServiceCollection" /> to
        ///     add the services to.
        /// </param>
        /// <returns>
        ///     The <see cref="IBrokerOptionsBuilder" /> so that additional calls can be chained.
        /// </returns>
        public static IBrokerOptionsBuilder AddOutbox <TOutboxWriter, TOutboxReader>(
            this IBrokerOptionsBuilder brokerOptionsBuilder)
            where TOutboxWriter : class, IOutboxWriter
            where TOutboxReader : class, IOutboxReader
        {
            Check.NotNull(brokerOptionsBuilder, nameof(brokerOptionsBuilder));

            brokerOptionsBuilder.SilverbackBuilder
            .AddScopedSubscriber <OutboxTransactionManager>()
            .Services
            .AddScoped <IOutboxWriter, TOutboxWriter>()
            .AddScoped <IOutboxReader, TOutboxReader>()
            .AddScoped <TransactionalOutboxBroker>();

            return(brokerOptionsBuilder);
        }
        /// <inheritdoc cref="IBrokerOptionsConfigurator{TBroker}.Configure" />
        public void Configure(IBrokerOptionsBuilder brokerOptionsBuilder)
        {
            Check.NotNull(brokerOptionsBuilder, nameof(brokerOptionsBuilder));

            brokerOptionsBuilder.SilverbackBuilder
            .AddSingletonBrokerBehavior <KafkaMessageKeyInitializerProducerBehavior>()
            .AddSingletonBrokerBehavior <KafkaPartitionResolverProducerBehavior>()
            .Services
            .AddTransient <IConfluentProducerBuilder, ConfluentProducerBuilder>()
            .AddTransient <IConfluentConsumerBuilder, ConfluentConsumerBuilder>()
            .AddSingleton <IConfluentProducersCache, ConfluentProducersCache>()
            .AddSingleton <IBrokerLogEnricher <KafkaProducerEndpoint>, KafkaLogEnricher>()
            .AddSingleton <IBrokerLogEnricher <KafkaConsumerEndpoint>, KafkaLogEnricher>()
            .AddSingleton <IBrokerActivityEnricher <KafkaProducerEndpoint>, KafkaActivityEnricher>()
            .AddSingleton <IBrokerActivityEnricher <KafkaConsumerEndpoint>, KafkaActivityEnricher>();
        }
        /// <summary>
        ///     <para>
        ///         Adds the necessary services to enable the <see cref="OffsetStoreExactlyOnceStrategy" /> using a
        ///         database table as store.
        ///     </para>
        ///     <para>
        ///         The <see cref="OffsetStoreExactlyOnceStrategy" /> stores uses an <see cref="IOffsetStore" /> to
        ///         keep track of the latest processed offsets and guarantee that each message is processed only once.
        ///     </para>
        /// </summary>
        /// <param name="brokerOptionsBuilder">
        ///     The <see cref="IBrokerOptionsBuilder" /> that references the <see cref="IServiceCollection" /> to
        ///     add the services to.
        /// </param>
        /// <returns>
        ///     The <see cref="IBrokerOptionsBuilder" /> so that additional calls can be chained.
        /// </returns>
        public static IBrokerOptionsBuilder AddOffsetStoreDatabaseTable(this IBrokerOptionsBuilder brokerOptionsBuilder)
        {
            Check.NotNull(brokerOptionsBuilder, nameof(brokerOptionsBuilder));

            return(brokerOptionsBuilder.AddOffsetStore <DbOffsetStore>());
        }
        /// <summary>
        ///     <para>
        ///         Adds the necessary services to enable the <see cref="OffsetStoreExactlyOnceStrategy" /> storing the
        ///         offsets in memory.
        ///     </para>
        ///     <para>
        ///         The <see cref="OffsetStoreExactlyOnceStrategy" /> stores uses an <see cref="IOffsetStore" /> to
        ///         keep track of the latest processed offsets and guarantee that each message is processed only once.
        ///     </para>
        /// </summary>
        /// <param name="brokerOptionsBuilder">
        ///     The <see cref="IBrokerOptionsBuilder" /> that references the <see cref="IServiceCollection" /> to
        ///     add the services to.
        /// </param>
        /// <returns>
        ///     The <see cref="IBrokerOptionsBuilder" /> so that additional calls can be chained.
        /// </returns>
        public static IBrokerOptionsBuilder AddInMemoryOffsetStore(this IBrokerOptionsBuilder brokerOptionsBuilder)
        {
            Check.NotNull(brokerOptionsBuilder, nameof(brokerOptionsBuilder));

            return(brokerOptionsBuilder.AddOffsetStore <InMemoryOffsetStore>());
        }
示例#17
0
 public void Configure(IBrokerOptionsBuilder brokerOptionsBuilder) =>
 brokerOptionsBuilder.SilverbackBuilder.AddSingletonBrokerBehavior <EmptyBehavior>();
示例#18
0
        /// <summary>
        ///     <para>
        ///         Adds the necessary services to enable the <see cref="LogExactlyOnceStrategy" /> storing the
        ///         offsets in memory.
        ///     </para>
        ///     <para>
        ///         The <see cref="LogExactlyOnceStrategy" /> stores uses an <see cref="IInboundLog" /> to
        ///         keep track of to keep track of each processed message and guarantee that each one is processed
        ///         only once.
        ///     </para>
        /// </summary>
        /// <param name="brokerOptionsBuilder">
        ///     The <see cref="IBrokerOptionsBuilder" /> that references the <see cref="IServiceCollection" /> to
        ///     add the services to.
        /// </param>
        /// <returns>
        ///     The <see cref="IBrokerOptionsBuilder" /> so that additional calls can be chained.
        /// </returns>
        public static IBrokerOptionsBuilder AddInMemoryInboundLog(this IBrokerOptionsBuilder brokerOptionsBuilder)
        {
            Check.NotNull(brokerOptionsBuilder, nameof(brokerOptionsBuilder));

            return(brokerOptionsBuilder.AddInboundLog <InMemoryInboundLog>());
        }
示例#19
0
        /// <summary>
        ///     <para>
        ///         Adds the necessary services to enable the <see cref="LogExactlyOnceStrategy" /> using a
        ///         database table as store.
        ///     </para>
        ///     <para>
        ///         The <see cref="LogExactlyOnceStrategy" /> stores uses an <see cref="IInboundLog" /> to
        ///         keep track of to keep track of each processed message and guarantee that each one is processed
        ///         only once.
        ///     </para>
        /// </summary>
        /// <param name="brokerOptionsBuilder">
        ///     The <see cref="IBrokerOptionsBuilder" /> that references the <see cref="IServiceCollection" /> to
        ///     add the services to.
        /// </param>
        /// <returns>
        ///     The <see cref="IBrokerOptionsBuilder" /> so that additional calls can be chained.
        /// </returns>
        public static IBrokerOptionsBuilder AddInboundLogDatabaseTable(this IBrokerOptionsBuilder brokerOptionsBuilder)
        {
            Check.NotNull(brokerOptionsBuilder, nameof(brokerOptionsBuilder));

            return(brokerOptionsBuilder.AddInboundLog <DbInboundLog>());
        }
示例#20
0
 /// <summary>
 ///     Registers Apache Kafka as message broker.
 /// </summary>
 /// <param name="brokerOptionsBuilder">
 ///     The <see cref="IBrokerOptionsBuilder" /> that references the <see cref="IServiceCollection" /> to
 ///     add the services to.
 /// </param>
 /// <returns>
 ///     The <see cref="IBrokerOptionsBuilder" /> so that additional calls can be chained.
 /// </returns>
 public static IBrokerOptionsBuilder AddKafka(this IBrokerOptionsBuilder brokerOptionsBuilder) =>
 brokerOptionsBuilder.AddBroker <KafkaBroker>();
示例#21
0
        /// <summary>
        ///     Adds the specified <see cref="IBroker" /> implementation to allow producing and consuming messages.
        /// </summary>
        /// <typeparam name="TBroker">
        ///     The type of the <see cref="IBroker" /> implementation to add.
        /// </typeparam>
        /// <param name="brokerOptionsBuilder">
        ///     The <see cref="IBrokerOptionsBuilder" /> that references the <see cref="IServiceCollection" /> to
        ///     add the services to.
        /// </param>
        /// <returns>
        ///     The <see cref="IBrokerOptionsBuilder" /> so that additional calls can be chained.
        /// </returns>
        public static IBrokerOptionsBuilder AddBroker <TBroker>(
            this IBrokerOptionsBuilder brokerOptionsBuilder)
            where TBroker : class, IBroker
        {
            Check.NotNull(brokerOptionsBuilder, nameof(brokerOptionsBuilder));

            if (!brokerOptionsBuilder.SilverbackBuilder.Services.ContainsAny <IBroker>())
            {
                // Configuration IHostedService
                brokerOptionsBuilder.SilverbackBuilder.Services
                .AddSingleton <IHostedService, BrokerConnectorService>()
                .AddSingleton <EndpointsConfiguratorsInvoker>();

                // Pipeline
                brokerOptionsBuilder.SilverbackBuilder.Services
                .AddTransient(typeof(IBrokerBehaviorsProvider <>), typeof(BrokerBehaviorsProvider <>));

                // Pipeline - Activity
                brokerOptionsBuilder.SilverbackBuilder
                .AddSingletonBrokerBehavior <ActivityProducerBehavior>()
                .AddSingletonBrokerBehavior <ActivityConsumerBehavior>();

                // Pipeline - Validation
                brokerOptionsBuilder.SilverbackBuilder
                .AddSingletonBrokerBehavior <ValidatorProducerBehavior>()
                .AddSingletonBrokerBehavior <ValidatorConsumerBehavior>();

                // Pipeline - Serialization
                brokerOptionsBuilder.SilverbackBuilder
                .AddSingletonBrokerBehavior <SerializerProducerBehavior>()
                .AddSingletonBrokerBehavior <DeserializerConsumerBehavior>();

                // Pipeline - Encryption
                brokerOptionsBuilder.SilverbackBuilder
                .AddSingletonBrokerBehavior <EncryptorProducerBehavior>()
                .AddSingletonBrokerBehavior <DecryptorConsumerBehavior>()
                .Services
                .AddSingleton <ISilverbackCryptoStreamFactory, SilverbackCryptoStreamFactory>();

                // Pipeline - Headers
                brokerOptionsBuilder.SilverbackBuilder
                .AddSingletonBrokerBehavior <HeadersWriterProducerBehavior>()
                .AddSingletonBrokerBehavior <HeadersReaderConsumerBehavior>()
                .AddSingletonBrokerBehavior <CustomHeadersMapperProducerBehavior>()
                .AddSingletonBrokerBehavior <CustomHeadersMapperConsumerBehavior>()
                .Services
                .AddSingleton <ICustomHeadersMappings>(new CustomHeadersMappings());

                // Pipeline - Sequences (Chunking, Batch, ...)
                brokerOptionsBuilder.SilverbackBuilder
                .AddSingletonBrokerBehavior <SequencerProducerBehavior>()
                .AddSingletonBrokerBehavior <SequencerConsumerBehavior>()
                .AddSingletonBrokerBehavior <RawSequencerConsumerBehavior>()
                .AddSingletonSequenceWriter <ChunkSequenceWriter>()
                .AddSingletonSequenceReader <ChunkSequenceReader>()
                .AddTransientSequenceReader <BatchSequenceReader>()
                .Services
                .AddTransient(typeof(ISequenceStore), typeof(DefaultSequenceStore));

                // Pipeline - Binary File
                brokerOptionsBuilder.SilverbackBuilder
                .AddSingletonBrokerBehavior <BinaryFileHandlerProducerBehavior>()
                .AddSingletonBrokerBehavior <BinaryFileHandlerConsumerBehavior>();

                // Pipeline - Producer basic logic
                brokerOptionsBuilder.SilverbackBuilder
                .AddSingletonBrokerBehavior <MessageEnricherProducerBehavior>()
                .AddSingletonBrokerBehavior <MessageIdInitializerProducerBehavior>()
                .AddSingletonBrokerBehavior <EndpointNameResolverProducerBehavior>();

                // Pipeline - Consumer basic logic
                brokerOptionsBuilder.SilverbackBuilder
                .AddSingletonBrokerBehavior <FatalExceptionLoggerConsumerBehavior>()
                .AddSingletonBrokerBehavior <TransactionHandlerConsumerBehavior>()
                .AddSingletonBrokerBehavior <ExactlyOnceGuardConsumerBehavior>()
                .AddSingletonBrokerBehavior <PublisherConsumerBehavior>();
            }

            // Register the broker as IBroker and the type itself, both resolving to the same instance
            brokerOptionsBuilder.SilverbackBuilder.Services
            .AddSingleton <IBroker, TBroker>()
            .AddSingleton(
                servicesProvider =>
                servicesProvider.GetServices <IBroker>().OfType <TBroker>().FirstOrDefault());

            FindOptionsConfigurator <TBroker>()?.Configure(brokerOptionsBuilder);

            return(brokerOptionsBuilder);
        }
        /// <summary>
        ///     <para>
        ///         Adds the necessary services to enable the <see cref="OutboxProduceStrategy" /> using a database
        ///         table as outbox.
        ///     </para>
        ///     <para>
        ///         The <see cref="OutboxProduceStrategy" /> stores the outbound messages into an intermediate outbox,
        ///         participating in the database transaction. The outbound messages become therefore transactional
        ///         with the side effects on the local database.
        ///     </para>
        /// </summary>
        /// <param name="brokerOptionsBuilder">
        ///     The <see cref="IBrokerOptionsBuilder" /> that references the <see cref="IServiceCollection" /> to
        ///     add the services to.
        /// </param>
        /// <returns>
        ///     The <see cref="IBrokerOptionsBuilder" /> so that additional calls can be chained.
        /// </returns>
        public static IBrokerOptionsBuilder AddOutboxDatabaseTable(this IBrokerOptionsBuilder brokerOptionsBuilder)
        {
            Check.NotNull(brokerOptionsBuilder, nameof(brokerOptionsBuilder));

            return(brokerOptionsBuilder.AddOutbox <DbOutboxWriter, DbOutboxReader>());
        }
 /// <summary>
 ///     Registers RabbitMQ as message broker.
 /// </summary>
 /// <param name="brokerOptionsBuilder">
 ///     The <see cref="IBrokerOptionsBuilder" /> that references the <see cref="IServiceCollection" /> to
 ///     add the services to.
 /// </param>
 /// <returns>
 ///     The <see cref="IBrokerOptionsBuilder" /> so that additional calls can be chained.
 /// </returns>
 public static IBrokerOptionsBuilder AddRabbit(this IBrokerOptionsBuilder brokerOptionsBuilder) =>
 brokerOptionsBuilder.AddBroker <RabbitBroker>();
示例#24
0
 /// <summary>
 ///     Registers Apache Mqtt as message broker.
 /// </summary>
 /// <param name="brokerOptionsBuilder">
 ///     The <see cref="IBrokerOptionsBuilder" /> that references the <see cref="IServiceCollection" /> to
 ///     add the services to.
 /// </param>
 /// <returns>
 ///     The <see cref="IBrokerOptionsBuilder" /> so that additional calls can be chained.
 /// </returns>
 public static IBrokerOptionsBuilder AddMqtt(this IBrokerOptionsBuilder brokerOptionsBuilder) =>
 brokerOptionsBuilder.AddBroker <MqttBroker>();