public SqlServerDocumentProvider(SqlServerDocumentProviderOptions <T> options) { EnsureArg.IsNotNull(options, nameof(options)); EnsureArg.IsNotNullOrEmpty(options.ConnectionString, nameof(options.ConnectionString)); EnsureArg.IsNotNull(options.SqlBuilder, nameof(options.SqlBuilder)); this.Options = options; this.Options.Serializer ??= new JsonNetSerializer(TypedJsonSerializerSettings.Create()); this.Logger = options.CreateLogger(this.GetType()); }
public static CommandRequestOptions UseAzureServiceBusQueue( this CommandRequestOptions options, string connectionString = null, string name = "commandrequests", TimeSpan?expiration = null, int?retries = null) { options.Context.Services.AddSingleton <IQueue <CommandRequestWrapper> >(sp => new AzureServiceBusQueue <CommandRequestWrapper>(o => o .Mediator(sp.GetRequiredService <IMediator>()) .Tracer(sp.GetService <ITracer>()) .LoggerFactory(sp.GetRequiredService <ILoggerFactory>()) .ConnectionString(connectionString.EmptyToNull() ?? options.Context.Configuration["naos:commands:azureServiceBusQueue:connectionString"]) .Serializer(new JsonNetSerializer(TypedJsonSerializerSettings.Create())) // needs type information in json to deserialize correctly (which is needed for mediator.send) .QueueName($"{name}-{HashAlgorithm.ComputeMd5Hash(options.Context.Descriptor.Name)}") .Expiration(expiration) .Retries(retries))); return(options); }
public static CommandRequestOptions UseRabbitMQQueue( this CommandRequestOptions options, string name = "commandrequests", TimeSpan?expiration = null, int?retries = null) { var queueName = typeof(CommandRequestWrapper).PrettyName(); var configuration = options.Context.Configuration.GetSection("naos:commands:rabbitMQQueue").Get <RabbitMQConfiguration>(); if (configuration?.Enabled == true) { var connectionFactory = new ConnectionFactory { Port = configuration.Port == 0 ? 5672 : configuration.Port, HostName = configuration.Host.IsNullOrEmpty() ? "localhost" : configuration.Host, // or 'rabbitmq' in docker-compose env UserName = configuration.UserName.IsNullOrEmpty() ? "guest" : configuration.UserName, Password = configuration.Password.IsNullOrEmpty() ? "guest" : configuration.Password, DispatchConsumersAsync = true, }; options.Context.Services.AddScoped <IQueue <CommandRequestWrapper> >(sp => { var provider = new RabbitMQProvider( sp.GetRequiredService <ILogger <RabbitMQProvider> >(), connectionFactory, configuration.RetryCount, $"{LogKeys.Queueing} {queueName} ({sp.GetService<Naos.Foundation.ServiceDescriptor>()?.Name})"); return(new RabbitMQQueue <CommandRequestWrapper>(o => o .Mediator(sp.GetService <IMediator>()) .Tracer(sp.GetService <ITracer>()) .LoggerFactory(sp.GetService <ILoggerFactory>()) .Serializer(new JsonNetSerializer(TypedJsonSerializerSettings.Create())) // needs type information in json to deserialize correctly (which is needed for mediator.send) .Provider(provider) .QueueName($"{options.Context.Descriptor.Name}-{name}") .Expiration(expiration) .Retries(retries))); }); } return(options); }