public static IServiceCollection AddMercuryMessaging(this IServiceCollection services, Action <RabbitSettings> configure) { services.AddSingleton(serviceProvider => { var settings = new RabbitSettings(); configure(settings); return(settings); }); services.AddSingleton <IConnectionFactory>(serviceProvider => { var settings = serviceProvider.GetRequiredService <RabbitSettings>(); return(new ConnectionFactory { HostName = settings.Host, UserName = settings.Username, Password = settings.Password, }); }); services.AddSingleton <IStructureInitializer, StructureInitializer>(); services.AddSingleton <IRequestPublisher <MercuryRequest <ExpandoObject> >, RequestPublisher <MercuryRequest <ExpandoObject> > >(); services.AddSingleton <IRequestConsumer <MercuryRequest <ExpandoObject> >, RequestConsumer <MercuryRequest <ExpandoObject> > >(); return(services); }
public RequestPublisher( IConnectionFactory connectionFactory, IStructureInitializer initializer, RabbitSettings settings) { this.connectionFactory = connectionFactory; this.initializer = initializer; this.settings = settings; }
public RequestConsumer( IConnectionFactory connectionFactory, IStructureInitializer initializer, ILogger <RequestConsumer <TRequest> > logger, RabbitSettings settings) { this.connectionFactory = connectionFactory; this.initializer = initializer; this.logger = logger.WithScope("QueueHost", settings.Host).WithScope("QueueName", settings.QueueName); this.settings = settings; messageBuffer = new BufferBlock <RequestMessage <TRequest> >(); deliveryTags = new ConcurrentDictionary <RequestMessage <TRequest>, ulong>(); }
public StructureInitializer(RabbitSettings settings) { lockObject = new object(); this.settings = settings.ThrowIfNull(nameof(settings)); }