示例#1
0
        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);
        }
示例#2
0
 public RequestPublisher(
     IConnectionFactory connectionFactory,
     IStructureInitializer initializer,
     RabbitSettings settings)
 {
     this.connectionFactory = connectionFactory;
     this.initializer       = initializer;
     this.settings          = settings;
 }
示例#3
0
        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>();
        }
示例#4
0
 public StructureInitializer(RabbitSettings settings)
 {
     lockObject    = new object();
     this.settings = settings.ThrowIfNull(nameof(settings));
 }