/// <summary> /// 开启重新发送的定时器。 /// </summary> private void StartPersistentTimer() { if (_persistance == null || Setting.RetryTimes == null || Setting.RetryTimes == 0) { return; } SingletonLocker.Lock(ref _timer, () => { return(new PersistentTimer(Setting.RetryDelayTime, () => { _persistance.ReadSubjects("rabbit", subject => { //如果超出重试次数 if (Setting.RetryTimes != null && subject.PublishRetries > Setting.RetryTimes) { return true; } try { Tracer.Debug($"Republish message of '{subject.Name}'."); PublishSubject(subject); return true; } catch (Exception) { return false; } }); })); }); }
private ISerializer GetSerializer() { return(SingletonLocker.Lock(ref _serializerFactory, this, () => { return new Func <ISerializer>(() => { ISerializer _serializer = null; if (Setting.SerializerType != null) { _serializer = Setting.SerializerType.New <ISerializer>(); } if (_serializer == null) { _serializer = ServiceProvider.TryGetService(() => SerializerFactory.CreateSerializer()); } if (_serializer == null) { var option = new JsonSerializeOption(); option.Converters.Add(new FullDateTimeJsonConverter()); _serializer = new JsonSerializer(option); } return _serializer; }); })()); }
private IConnection GetConnection() { _connectionLazy = SingletonLocker.Lock(ref _connectionLazy, () => new AliveObject <IConnection>(() => CreateConnectionFactory().CreateConnection(), new AliveCheckPolicy <IConnection>(s => s.IsOpen, TimeSpan.FromSeconds(5)))); return(_connectionLazy.Value); }
/// <summary> /// 获取 <see cref="IMapper"/> 实例,此实例为单例。 /// </summary> /// <returns></returns> public static IMapper GetMapper() { return(SingletonLocker.Lock(ref mapper, locker, () => { var mapperConfiguration = new MapperConfiguration(c => { configurators.ForEach(s => s(c)); }); return mapperConfiguration.CreateMapper(); })); }