示例#1
0
        public static void AddRMQEventBus(this IServiceCollection services, IConfiguration configuration)
        {
            services.AddSingleton(provider => RMQSettings.Build(configuration));
            services.AddSingleton <IRMQConnectionManager, RMQConnectionManager>();

            services.AddRabbitMQEvent <EventBusRMQ>();
        }
示例#2
0
        public EventBusRMQ(RMQSettings settings, IServiceProvider service, IRMQConnectionManager connectionManager, ISubscriptionsManager subscriptionManager)
        {
            this.settings            = settings;
            this.serviceCollection   = service;
            this.connectionmanager   = connectionManager;
            this.subscriptionManager = subscriptionManager;

            this.channel = CreateChannel();
            this.subscriptionManager.OnEventRemoved += SubsManager_OnEventRemoved;
        }
示例#3
0
        public static IServiceCollection AddQueueService(this IServiceCollection services, IConfiguration configuration)
        {
            var rmqSettings = new RMQSettings();

            configuration.GetSection(nameof(RMQSettings)).Bind(rmqSettings);

            if (rmqSettings.Enabled && !String.IsNullOrEmpty(rmqSettings.ConnectionString))
            {
                rmqSettings.ConnectionString = string.Format(rmqSettings.ConnectionString,
                                                             File.ReadAllText(Environment.GetEnvironmentVariable(nameof(EnvironmentVariables.RMQ_USER_FILE))),
                                                             File.ReadAllText(Environment.GetEnvironmentVariable(nameof(EnvironmentVariables.RMQ_PWD_FILE))),
                                                             Environment.GetEnvironmentVariable(nameof(EnvironmentVariables.RMQ_HOST)),
                                                             Environment.GetEnvironmentVariable(nameof(EnvironmentVariables.RMQ_PORT)));

                services.AddSingleton(rmqSettings);

                services.AddSingleton <DefaultObjectPoolProvider>();
                services.AddSingleton <IPooledObjectPolicy <IModel>, RabbitPooledObjectPolicy>();
                services.AddSingleton <IMessageProducerService, RMQMessageProducerService>();
                services.AddSingleton <IMessageConsumerService, RMQMessageConsumerService>();
                // services.AddTransient (s => {
                //     var factory = new ConnectionFactory {
                //         Uri = new Uri (rmqSettings.ConntectionString)
                //     };
                //     var connection = factory.CreateConnection ();
                //     var channel = connection.CreateModel ();
                //     return new MessageProducerService (channel);
                // });
            }
            else
            {
                services.AddSingleton(rmqSettings);
                services.AddSingleton <IMessageProducerService, DefaultMessageProducerService>();
                services.AddSingleton <IMessageConsumerService, DefaultMessageConsumerService>();
            }
            return(services);
        }
示例#4
0
 public RMQConnectionManager(RMQSettings settings)
 {
     this.settings = settings;
     connection    = ClientConnectionFactory.CreateConnection(settings.HostName);
 }
示例#5
0
 public RMQMessageConsumerService(IPooledObjectPolicy <IModel> objectPolicy, RMQSettings rmqSettings)
 {
     _objectPool  = new DefaultObjectPool <IModel>(objectPolicy, Environment.ProcessorCount * 2);;
     _rmqSettings = rmqSettings;
 }
示例#6
0
 public RabbitPooledObjectPolicy(RMQSettings rmqSettings)
 {
     _rabbitMqSettings = rmqSettings ?? throw new NullReferenceException(nameof(RMQSettings));
     _connection       = GetConnection();
     DeclareSchema();
 }