public static IServiceBusBuilder UseConsumerRedelivery(this IServiceBusBuilder config, params TimeSpan[] sleepDurations)
 {
     config.ThrowIfNull(nameof(config));
     sleepDurations.ThrowIfNull(nameof(sleepDurations));
     config.Services.AddSingleton <IConsumerRedeliveryPipelineFactory>(new RedeliveryPipelineFactory(sleepDurations));
     return(config);
 }
예제 #2
0
 public static IServiceBusBuilder UseTopology <T>(this IServiceBusBuilder config)
     where T : class, IAzureTopologyBuilder
 {
     config.ThrowIfNull(nameof(config));
     config.Services.AddSingleton <IAzureTopologyBuilder, T>();
     return(config);
 }
 public static IServiceBusBuilder UsePublisherRetry(this IServiceBusBuilder config, IAsyncPolicy policy)
 {
     config.ThrowIfNull(nameof(config));
     policy.ThrowIfNull(nameof(policy));
     config.Services.AddSingleton <IPublisherRetryPipelineFactory>(new PublisherRetryPipelineFactory(policy));
     return(config);
 }
예제 #4
0
        public static IServiceBusBuilder AddConsumer(this IServiceBusBuilder builder, Type consumerType)
        {
            builder.ThrowIfNull(nameof(builder));
            consumerType.ThrowIfNull(nameof(consumerType));
            if (!typeof(IConsumer).IsAssignableFrom(consumerType))
            {
                throw new ArgumentException($"Consumer must implement {typeof(IConsumer<>).FullName}");
            }
            if (!consumerType.IsClass)
            {
                throw new ArgumentException($"Consumer must be reference type.");
            }
            if (consumerType.IsAbstract)
            {
                throw new ArgumentException($"Consumer must not be abstract or static.");
            }

            var consumerEmptyInterface = typeof(IConsumer <>);

            foreach (var consumerInterface in consumerType.GetInterfaces())
            {
                if (consumerInterface.GenericTypeArguments.Length > 0 && consumerEmptyInterface == consumerInterface.GetGenericTypeDefinition())
                {
                    var messageType  = consumerInterface.GenericTypeArguments[0];
                    var pipelineType = typeof(DefaultConsumerPipeline <,>).MakeGenericType(consumerType, messageType);
                    builder.Services.AddSingleton <IConsumerDefinition>(new DefaultConsumerDefinition(consumerType, consumerInterface, messageType, pipelineType));
                    builder.Services.AddScoped(consumerType);
                    builder.Services.AddScoped(pipelineType);
                }
            }
            return(builder);
        }
예제 #5
0
 public static IServiceBusBuilder UseMongoTransport(this IServiceBusBuilder builder, MongoTransportSettings settings)
 {
     builder.ThrowIfNull(nameof(builder))
     .UsePublisherTransport <MongoPublisherTransport>()
     .UseConsumerTransport <MongoConsumerTransport>();
     builder.Services.AddSingleton(new MongoClientFactory(settings));
     return(builder);
 }
예제 #6
0
 public static IServiceBusBuilder UseAzureTransport(this IServiceBusBuilder config, AzureTransportSettings settings)
 {
     config.ThrowIfNull(nameof(config))
     .UseConsumerTransport <AzureConsumerTransport>()
     .UsePublisherTransport <AzurePublisherTransport>();
     config.Services.AddSingleton(new AzureClientFactory(settings));
     return(config);
 }
예제 #7
0
        public static IServiceBusBuilder AddConsumers(this IServiceBusBuilder builder, params Assembly[] consumerAssemblies)
        {
            builder.ThrowIfNull(nameof(builder));
            if (consumerAssemblies is null || consumerAssemblies.Length == 0)
            {
                consumerAssemblies = AppDomain.CurrentDomain.GetAssemblies();
            }
            var consumers = consumerAssemblies.SelectMany(a => a.DefinedTypes)
                            .Where(t => t.IsClass && !t.IsAbstract && !t.ContainsGenericParameters)
                            .Where(t => typeof(IConsumer).IsAssignableFrom(t))
                            .ToList();
            var nestedConsumers = consumerAssemblies.SelectMany(a => a.DefinedTypes)
                                  .Where(t => t.DeclaringType is null && t.IsClass && !t.IsAbstract && !t.ContainsGenericParameters)
                                  .SelectMany(t => t.GetNestedConsumers())
                                  .ToList();
            var distinctConsumers      = consumers.Concat(nestedConsumers).Distinct().ToList();
            var consumerEmptyInterface = typeof(IConsumer <>);

            foreach (var consumerType in distinctConsumers)
            {
                builder.AddConsumer(consumerType);
            }
            return(builder);
        }
 public static IServiceBusBuilder UseConsumerConcurrencyLimiter(this IServiceBusBuilder config, ConcurrencyDefinition definition)
 {
     config.ThrowIfNull(nameof(config));
     config.Services.AddSingleton <IConsumerConcurrencyPipelineFactory>(new ConsumerConcurrencyPipelineFactory(definition));
     return(config);
 }
 public static IServiceBusBuilder UseConsumerTransaction(this IServiceBusBuilder config)
 {
     config.ThrowIfNull(nameof(config));
     config.Services.AddSingleton <IConsumerTransactionPipelineFactory, TransactionPipelineFactory>();
     return(config);
 }
 public static IServiceBusBuilder UseConsumerRedelivery(this IServiceBusBuilder config, int retryCount, Func <int, TimeSpan> sleepDurationProvider)
 {
     config.ThrowIfNull(nameof(config));
     config.Services.AddSingleton <IConsumerRedeliveryPipelineFactory>(new RedeliveryPipelineFactory(retryCount, sleepDurationProvider));
     return(config);
 }
예제 #11
0
 public static IServiceBusBuilder AddConsumer <T>(this IServiceBusBuilder builder) where T : IConsumer
 {
     return(builder.ThrowIfNull(nameof(builder))
            .AddConsumer(typeof(T)));
 }
 public static IServiceBusBuilder UseConsumerTransport <T>(this IServiceBusBuilder config) where T : class, IConsumerTransport
 {
     config.ThrowIfNull(nameof(config));
     config.Services.AddTransient <IConsumerTransport, T>();
     return(config);
 }
 public static IServiceBusBuilder UseMemoryTransport(this IServiceBusBuilder config)
 {
     return(config.ThrowIfNull(nameof(config))
            .UseConsumerTransport <MemoryConsumerTransport>()
            .UsePublisherTransport <MemoryPublisherTransport>());
 }
예제 #14
0
 public static IServiceBusBuilder UseHostedServiceBus(this IServiceBusBuilder config)
 {
     config.ThrowIfNull(nameof(config));
     config.Services.AddHostedService <DefaultHostedService>();
     return(config);
 }
예제 #15
0
 public static IServiceBusBuilder UseTopology(this IServiceBusBuilder config, IAzureTopologyBuilder builder)
 {
     config.ThrowIfNull(nameof(config));
     config.Services.AddSingleton(builder);
     return(config);
 }