private void ConfigureRabbitMq(IServiceCollection services) { var options = new RabbitMqOptions(); var section = Configuration.GetSection("rabbitmq"); section.Bind(options); var client = BusClientFactory.CreateDefault(options); services.AddSingleton <IBusClient>(_ => client); services.AddScoped <ICommandHandler <CalculateValueCommand>, CalculateValueCommandHandler>(); }
public RabbitMqHandler(IRabbitMqClient rabbitMqClient, IContextBuilder contextBuilder, RabbitMqOptions options, IRequestProcessor requestProcessor, IPayloadBuilder payloadBuilder, IPayloadValidator payloadValidator, ILogger <RabbitMqHandler> logger) { _rabbitMqClient = rabbitMqClient; _options = options; _contextBuilder = contextBuilder; _requestProcessor = requestProcessor; _payloadBuilder = payloadBuilder; _payloadValidator = payloadValidator; _logger = logger; }
public RabbitMqClient(IConnection connection, IContextProvider contextProvider, IRabbitMqSerializer serializer, RabbitMqOptions options, ILogger <RabbitMqClient> logger) { _connection = connection; _contextProvider = contextProvider; _serializer = serializer; _logger = logger; _contextEnabled = options.Context?.Enabled == true; _loggerEnabled = options.Logger?.Enabled ?? false; _spanContextHeader = options.GetSpanContextHeader(); _maxChannels = options.MaxProducerChannels <= 0 ? 1000 : options.MaxProducerChannels; }
public static LinFxBuilder AddRabbitMq(this LinFxBuilder builder, Action <RabbitMqOptions> optionsAction) { Check.NotNull(builder, nameof(builder)); Check.NotNull(optionsAction, nameof(optionsAction)); var options = new RabbitMqOptions(); optionsAction?.Invoke(options); builder.Services.Configure(optionsAction); return(builder.AddRabbitMq()); }
public RabbitMqAdapterReceiver(IRabbitMqConnectorFactory rmqConnectorFactory, QueueId queueId, IStreamQueueMapper mapper, IQueueDataAdapter <RabbitMqMessage, IEnumerable <IBatchContainer> > dataAdapter, RabbitMqOptions rmqOptions) { _rmqConnectorFactory = rmqConnectorFactory; _queueId = queueId; _mapper = mapper; _dataAdapter = dataAdapter; _logger = _rmqConnectorFactory.LoggerFactory.CreateLogger($"{typeof(RabbitMqAdapterReceiver).FullName}.{queueId}"); _sequenceId = 0; _pending = new List <PendingDelivery>(); _currentGroup = new Queue <IBatchContainer>(); _rmqOptions = rmqOptions; }
public static void AddRabbitMq(this IServiceCollection service, IConfiguration configuration) { var options = new RabbitMqOptions(); var section = configuration.GetSection("rabbitmq"); section.Bind(options); var client = RawRabbitFactory.CreateSingleton(new RawRabbitOptions { ClientConfiguration = options }); service.AddSingleton <IBusClient> (_ => client); }
public RabbitMqClient( IConnection connection, IBrokerSerializer serializer, RabbitMqOptions options, ILogger <RabbitMqClient> logger) { _connection = connection; _serializer = serializer; _logger = logger; _isLoggerEnabled = options.Logger.Enabled; _maxChannels = options.MaxProducerChannels <= 0 ? 1000 : options.MaxProducerChannels; }
public static void AddMassTransitSetup(this IServiceCollection services, RabbitMqOptions options) { var busControl = Bus.Factory.CreateUsingRabbitMq(cfg => { cfg.Host(new Uri(options.Url), h => { h.Username(options.Username); h.Password(options.Password); }); }); services.AddSingleton(busControl); }
public RabbitMqClient(IConnection connection, IContextProvider contextProvider, IRabbitMqSerializer serializer, RabbitMqOptions options, ILogger <RabbitMqClient> logger) { _contextProvider = contextProvider; _serializer = serializer; _logger = logger; _contextEnabled = options.Context?.Enabled == true; _channel = connection.CreateModel(); _loggerEnabled = options.Logger?.Enabled ?? false; _spanContextHeader = string.IsNullOrWhiteSpace(options.SpanContextHeader) ? "span_context" : options.SpanContextHeader; }
public void DefaultCtor_IsValid() { var options = new RabbitMqOptions(); Assert.Equal(string.Empty, options.ConnectionName); Assert.Equal(new Uri("rabbitmq:/"), options.HostAddress); Assert.Null(options.Host); Assert.Null(options.Port); Assert.Null(options.VirtualHost); Assert.Null(options.Heartbeat); Assert.Null(options.Username); Assert.Null(options.Password); }
public MessageBroker(IBusPublisher busPublisher, ICorrelationContextAccessor contextAccessor, IHttpContextAccessor httpContextAccessor, IMessagePropertiesAccessor messagePropertiesAccessor, RabbitMqOptions options, ITracer tracer) { _busPublisher = busPublisher; _contextAccessor = contextAccessor; _httpContextAccessor = httpContextAccessor; _messagePropertiesAccessor = messagePropertiesAccessor; _tracer = tracer; _spanContextHeader = string.IsNullOrWhiteSpace(options.SpanContextHeader) ? "span_context" : options.SpanContextHeader; }
public RabbitMqClient(IConnection connection, RabbitMqOptions options, ILogger <RabbitMqClient> logger) { _connection = connection; _logger = logger; _messageContextEnabled = options.MessageContext?.Enabled == true; _messageContextHeader = string.IsNullOrWhiteSpace(options.MessageContext?.Header) ? "message_context" : options.MessageContext.Header; _loggerEnabled = options.Logger?.Enabled == true; _spanContextHeader = string.IsNullOrWhiteSpace(options.SpanContextHeader) ? "span_context" : options.SpanContextHeader; }
public static IServiceCollection AddRabbitMqHelper(this IServiceCollection services, Action <RabbitMqOptions> build, IConfiguration configuration) { var options = new RabbitMqOptions(); options.Configuration = configuration; build(options); services.AddSingleton(options); services.AddSingleton <RabbitMqConnectionTable>(); services.AddSingleton <RabbitMqHelper>(); return(services); }
private void ConfigureRabbitMqServices(IServiceCollection services) { var rabbitMqOptions = new RabbitMqOptions(); var rabbitMqOptionsSection = Configuration.GetSection("rabbitmq"); rabbitMqOptionsSection.Bind(rabbitMqOptions); var rabbitMqClient = BusClientFactory.CreateDefault(rabbitMqOptions); services.Configure <RabbitMqOptions>(rabbitMqOptionsSection); services.AddSingleton <IBusClient>(_ => rabbitMqClient); services.AddScoped <IEventHandler <ReportCreated>, ReportCreatedHandler>(); services.AddScoped <IEventHandler <CreateReportRejected>, CreateReportRejectedHandler>(); }
private void ConfigureRabbitMq(IServiceCollection services) { var options = new RabbitMqOptions(); var section = Configuration.GetSection("rabbitmq"); section.Bind(options); services.Configure <RabbitMqOptions>(section); var client = BusClientFactory.CreateDefault(options); services.AddSingleton <IBusClient>(client); services.AddScoped <IEventHandler <RecordCreated>, RecordCreatedHandler>(); services.AddScoped <IEventHandler <CreateRecordFailed>, CreateRecordFailedHandler>(); }
private void ConfigureRabbitMq(IServiceCollection serviceCollection) { var options = new RabbitMqOptions(); var section = Configuration.GetSection("rabbitmq"); section.Bind(options); System.Console.Out.WriteLine(string.Join(", ", options.Hostnames)); var client = BusClientFactory.CreateDefault(options); serviceCollection.AddSingleton <IBusClient>(_ => client); serviceCollection.AddTransient <IEventHandler <ValueCalculated>, ValueCalculatedEventHandler>(); }
public void Initialize() { mockCommandQueuePolicy = new Mock <IQueuePolicy>(); mockEventQueuePolicy = new Mock <IQueuePolicy>(); _options = new RabbitMqOptions { CommandQueuePolicy = mockCommandQueuePolicy.Object, EventQueuePolicy = mockEventQueuePolicy.Object }; _connectionDescriptor = Fixture.Create <MassTransitConnectionDescriptor>(); }
public static void AddRabbitMq(this IServiceCollection services, IConfiguration configuration) { var options = new RabbitMqOptions(); var section = configuration.GetSection("rabbitmq"); section.Bind(options); var client = RawRabbitFactory.CreateSingleton(new RawRabbitOptions { ClientConfiguration = options }); services.AddSingleton <ImessageBus>(new RabbitQueueMessageBus(client)); }
public QueuedSqlServerToRabbitMQService(IBackgroundTaskQueue taskQueue, ILogger <QueuedSqlServerToRabbitMQService> logger, IMapper mapper, RabbitMqOptions rabbitOptions, IServiceProvider services) { _taskQueue = taskQueue; _logger = logger; _mapper = mapper; _rabbitOptions = rabbitOptions; Services = services; InitRabbitMQ(); }
public RabbitMqHandler(IRabbitMqClient rabbitMqClient, IContextBuilder contextBuilder, ISpanContextBuilder spanContextBuilder, IRequestProcessor requestProcessor, IPayloadBuilder payloadBuilder, IPayloadValidator payloadValidator, RabbitMqOptions options, IServiceProvider serviceProvider) { _rabbitMqClient = rabbitMqClient; _contextBuilder = contextBuilder; _spanContextBuilder = spanContextBuilder; _requestProcessor = requestProcessor; _payloadBuilder = payloadBuilder; _payloadValidator = payloadValidator; _options = options; _requestHooks = serviceProvider.GetServices <IRequestHook>(); _responseHooks = serviceProvider.GetServices <IResponseHook>(); }
public void AssignProperties_HostAddressIsValid() { var options = new RabbitMqOptions { Host = "localhost", Port = 8080, VirtualHost = "vhost", }; Assert.Equal("localhost", options.HostAddress.Host); Assert.Equal("localhost:8080", options.HostAddress.Authority); Assert.Equal(8080, options.HostAddress.Port); Assert.Equal("/vhost", options.HostAddress.AbsolutePath); }
private static BusClient RabbitMqClientFactory(IConfiguration configuration) { var options = new RabbitMqOptions(); var section = configuration.GetSection("rabbitmq"); section.Bind(options); return(RawRabbitFactory.CreateSingleton(new RawRabbitOptions { ClientConfiguration = options, Plugins = p => p .UseGlobalExecutionId() .UseMessageContext <MessageContext>() })); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { // Add framework services. services.AddMvc(); services.AddOptions(); var rabbitMqOptions = new RabbitMqOptions(); var rabbitMqOptionsSection = Configuration.GetSection("rabbitmq"); rabbitMqOptionsSection.Bind(rabbitMqOptions); var rabbitMqClient = BusClientFactory.CreateDefault(rabbitMqOptions); services.Configure <RabbitMqOptions>(rabbitMqOptionsSection); services.AddScoped <IBusClient>(_ => rabbitMqClient); }
public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .ConfigureServices((hostContext, services) => { IConfiguration configuration = hostContext.Configuration; RabbitMqOptions rabbitOptions = configuration.GetSection("RabbitMQ").Get <RabbitMqOptions>(); services.AddSingleton(rabbitOptions); services.AddSingleton <IBackgroundTaskQueue, BackgroundTaskQueue>(); services.AddHostedService <QueuedSqlServerToRabbitMQService>(); services.AddAutoMapper(typeof(Program)); services.AddDIConfiguration(); });
private void ConfigureRabbitMq(IServiceCollection services) { var options = new RabbitMqOptions(); var section = Configuration.GetSection("rabbitmq"); section.Bind(options); var client = RawRabbitFactory.CreateSingleton(new RawRabbitOptions { ClientConfiguration = options }); services.AddSingleton <IBusClient>(_ => client); services.AddScoped <IEventHandler <ValueCalculated>, ValueCalculatedHandler>(); }
public RabbitMqSubscriber(IServiceProvider serviceProvider) { _serviceProvider = serviceProvider; _busPublisher = serviceProvider.GetRequiredService <IBusPublisher>(); _conventionProvider = serviceProvider.GetRequiredService <IConventionProvider>(); _channel = serviceProvider.GetRequiredService <IConnection>().CreateModel(); _jsonSerializer = serviceProvider.GetRequiredService <IJsonSerializer>(); _logger = serviceProvider.GetService <ILogger <RabbitMqSubscriber> >(); _options = serviceProvider.GetRequiredService <RabbitMqOptions>(); _qosOptions = _options?.Qos ?? new RabbitMqOptions.QosOptions(); if (_qosOptions.PrefetchCount < 1) { _qosOptions.PrefetchCount = 1; } }
public void OutboundEncoding_is_correctly_bound(Encoding encoding) { var settings = new Dictionary <string, string> { [$"{nameof(RabbitMqOptions.OutboundEncoding)}"] = encoding.WebName }; var configuration = CreateConfiguration(settings); var sut = new RabbitMqOptions(); configuration.Bind(sut); Assert.That(sut.OutboundEncoding, Is.EqualTo(encoding.WebName)); }
public void EventExchange_Properties_is_correctly_bound(string key, string value) { var settings = new Dictionary <string, string> { [$"{nameof(RabbitMqOptions.EventExchange)}:{nameof(ExchangeOptions.Properties)}:{key}"] = value }; var configuration = CreateConfiguration(settings); var sut = new RabbitMqOptions(); configuration.Bind(sut); Assert.That(sut.EventExchange.Properties[key], Is.EqualTo(value)); }
public void UnackedMessageCountLimit_is_correctly_bound_when_no_value_is_provided() { var settings = new Dictionary <string, string> { [$"{nameof(RabbitMqOptions.UnackedMessageCountLimit)}"] = null }; var configuration = CreateConfiguration(settings); var sut = new RabbitMqOptions(); configuration.Bind(sut); Assert.That(sut.UnackedMessageCountLimit, Is.Null); }
public void ConnectionString_is_correctly_bound(string connectionString) { var settings = new Dictionary <string, string> { [$"{nameof(RabbitMqOptions.ConnectionString)}"] = connectionString }; var configuration = CreateConfiguration(settings); var sut = new RabbitMqOptions(); configuration.Bind(sut); Assert.That(sut.ConnectionString.Value, Is.EqualTo(connectionString)); }