예제 #1
0
        /// <summary>
        /// 配置文件初始化
        /// </summary>
        /// <param name="configPath">文件路径</param>
        public static void Configure(string configPath = "")
        {
            if (!File.Exists(configPath))
            {
                string errMsg = $"配置文件:{configPath}不存在!!!";
                throw new FileNotFoundException(errMsg);
            }

            //加载配置文件
            Config = null;//AppSettings.GetCustomModel<RabbitmqOptions>(fileDir, fileName);
            if (Config == null)
            {
                string errMsg = $"配置文件:{configPath}初始化异常!!!";
                throw new TypeInitializationException("RabbitmqConfig", null);
            }

            //创建链接工厂
            var connectionStrings = Config.ConnectionString;

            ConnectionFactory = new ConnectionFactory()
            {
                Port = connectionStrings.Port,
                AutomaticRecoveryEnabled = true,
                HostName           = connectionStrings.Host,
                Password           = connectionStrings.Password,
                UserName           = connectionStrings.UserName,
                RequestedHeartbeat = connectionStrings.TimeOut
            };
            //创建链接
            Connection = ConnectionFactory.CreateConnection();
        }
예제 #2
0
        public static void AddRabbitMq(this IServiceCollection serviceCollection, IConfiguration configuration)
        {
            var options = new RabbitmqOptions();

            var section = configuration.GetSection("rabbitmq");

            section.Bind(options);

            Console.WriteLine(section);

            var client = RawRabbitFactory.CreateSingleton(new RawRabbitOptions {
                ClientConfiguration = options
            });

            serviceCollection.AddSingleton <IBusClient>(_ => client);
        }
 public ServiceBusRepository(IBus bus, IOptions <RabbitmqOptions> rabbitmqOptions)
 {
     _bus             = bus;
     _rabbitmqOptions = rabbitmqOptions.Value;
 }
 public ProducingService(IOptions <RabbitmqOptions> rabbitmqOptionsAccessor)
 {
     _rabbitmqOptions = rabbitmqOptionsAccessor.Value;
 }