public static void AddConsumerWithDefaultEndpoint <T>(this IContainerBuilderBusConfigurator builder) where T : class, IConsumer { builder.AddConsumer <T>().Endpoint(e => { e.Name = typeof(T).FullName; e.PrefetchCount = 1; }); }
public static void UseRabbitMq(this IContainerBuilderBusConfigurator builder) { builder.UsingRabbitMq((context, config) => { var rabbitConfig = context.GetService <IRabbitMqConfig>(); config.Host(rabbitConfig.Host, rabbitConfig.VirtualHost, h => { h.Username(rabbitConfig.Username); h.Password(rabbitConfig.Password); }); config.ConfigureEndpoints(context); }); }
public static void ConfigureBus( this IContainerBuilderBusConfigurator configurator, AppSettings.RabbitMqBusConfig rabbitMqBusConfig, AppSettings.AzureBusConfig azureBusConfig, AppSettings.BusConfigSettings busConfigSettings) { switch (busConfigSettings.BusTransport.ToLower()) { //case "azure": // configurator.UsingAzureServiceBus((context, cfg) => // { // cfg.Host(new Uri(azureBusConfig.HostUri), host => // { // host.TokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider( // azureBusConfig.KeyName, // azureBusConfig.PrimaryKey, // TimeSpan.FromDays(1), // TokenScope.Namespace); // }); // BusConfiguration(context, cfg, busConfigSettings); // }); // break; case "rabbitmq": configurator.UsingRabbitMq((context, cfg) => { cfg.Host(new Uri(rabbitMqBusConfig.HostUri), host => { host.Username(rabbitMqBusConfig.Username); host.Password(rabbitMqBusConfig.Password); }); BusConfiguration(context, cfg, busConfigSettings); }); break; default: throw new NotSupportedException($"Bus transport {busConfigSettings.BusTransport} is not supported"); } }
/// <summary> /// Adds <see cref="ITransactionalBus" /> to the container with scoped lifetime, which can be used to release the messages to the bus /// immediately after a transaction commit. This has a very limited purpose and is not meant for general use. /// It is recommended this is scoped within a unit of work (e.g. Http Request) /// </summary> public static void AddTransactionalBus <TBus>(this IContainerBuilderBusConfigurator <TBus> busConfigurator) where TBus : class, IBus { busConfigurator.Builder.Register <ITransactionalBus>(provider => new TransactionalBus(provider.Resolve <TBus>())) .InstancePerLifetimeScope(); }
/// <summary> /// Adds <see cref="ITransactionalBus" /> to the container with singleton lifetime, which can be used instead of <see cref="IBus" /> to enlist /// published/sent messages in the current transaction. It isn't truly transactional, but delays the messages until /// the transaction being to commit. This has a very limited purpose and is not meant for general use. /// </summary> public static void AddTransactionalEnlistmentBus <TBus>(this IContainerBuilderBusConfigurator <TBus> busConfigurator) where TBus : class, IBus { busConfigurator.Builder.Register <ITransactionalBus>(provider => new TransactionalEnlistmentBus(provider.Resolve <TBus>())) .SingleInstance(); }
/// <summary> /// Adds <see cref="ITransactionalBus"/> to the container with scoped lifetime, which can be used to release the messages to the bus /// immediately after a transaction commit. This has a very limited purpose and is not meant for general use. /// It is recommended this is scoped within a unit of work (e.g. Http Request) /// </summary> public static void AddTransactionalBus(this IContainerBuilderBusConfigurator builder) { builder.Builder.Register(c => new TransactionalBus(c.Resolve <IBus>())) .InstancePerLifetimeScope() .As <ITransactionalBus>(); }
/// <summary> /// Adds <see cref="ITransactionalBus"/> to the container with singleton lifetime, which can be used instead of <see cref="IBus"/> to enlist /// published/sent messages in the current transaction. It isn't truly transactional, but delays the messages until /// the transaction being to commit. This has a very limited purpose and is not meant for general use. /// </summary> public static void AddTransactionalEnlistmentBus(this IContainerBuilderBusConfigurator builder) { builder.Builder.Register(c => new TransactionalEnlistmentBus(c.Resolve <IBus>())) .SingleInstance() .As <ITransactionalBus>(); }