private static void Open(MqConfig config) { if (_conn != null) { return; } lock (LockObj) { var factory = new ConnectionFactory { //设置主机名 HostName = config.Host, //设置心跳时间 RequestedHeartbeat = config.HeartBeat, //设置自动重连 AutomaticRecoveryEnabled = config.AutomaticRecoveryEnabled, //重连时间 NetworkRecoveryInterval = config.NetworkRecoveryInterval, //用户名 UserName = config.UserName, //密码 Password = config.Password }; factory.AutomaticRecoveryEnabled = true; factory.NetworkRecoveryInterval = new TimeSpan(1000); _conn = _conn ?? factory.CreateConnection(); } }
public RabbitMqService(MqConfig config) { Open(config); }