/// <summary> /// 创建服务总线 /// </summary> /// <param name="config"></param> /// <returns></returns> public static IBus CreateEventBus() { var config = SystemJsonConfigManage.GetInstance().AppSettings["MeessageService"]; if (string.IsNullOrEmpty(config)) { throw new Exception("消息地址未配置"); } if (bus == null && !string.IsNullOrEmpty(config)) { lock (lockHelper) { if (bus == null) { bus = RabbitHutch.CreateBus(config); } } } return(bus); }
/// <summary> /// 获取Redis缓存实例 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="action"></param> /// <returns></returns> public static CacheManager.Core.ICacheManager <T> GetRedisInstace() { var rediscon = SystemJsonConfigManage.GetInstance().AppSettings["RedisCon"].ToSafeString(); rediscon.CheckNotNullOrEmpty("错误: appsettings.json->appsetting下未配置节点:RedisCon").ThrowUserFriendlyException(); if (redisCacheSingleton == null) { lock (lockobjk) { if (redisCacheSingleton == null) { redisCacheSingleton = (CacheManager.Core.CacheFactory.Build <T>(settings => { settings .WithRedisConfiguration("redis", config => //Redis缓存配置 { config.WithAllowAdmin() .WithDatabase(0) .WithEndpoint((rediscon.Split(':')[0]).ToSafeString(""), (rediscon.Split(':')[1]).ToSafeInt32(0)); }) .WithMaxRetries(1000) //尝试次数 .WithRetryTimeout(100) //尝试超时时间 .WithJsonSerializer() .WithRedisCacheHandle("redis", true); //redis缓存handle })); return(redisCacheSingleton); } else { return(redisCacheSingleton); } } } else { return(redisCacheSingleton); } }
/// <summary> /// 获取二级缓存实例,一级缓存本地内存,二级缓存Redis。 本地内存的依赖蓝本数据为Redis为准。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="action"></param> /// <returns></returns> public static CacheManager.Core.ICacheManager <T> GetMultilevelInstace() { var rediscon = SystemJsonConfigManage.GetInstance().AppSettings["RedisCon"].ToSafeString(); rediscon.CheckNotNullOrEmpty("错误: appsettings.json->appsetting下未配置节点:RedisCon").ThrowUserFriendlyException(); return(CacheManager.Core.CacheFactory.Build <T>(settings => { settings.WithMicrosoftMemoryCacheHandle("inProcessCache") //内存缓存Handle .And .WithRedisConfiguration("redis", config => //Redis缓存配置 { config.WithAllowAdmin() .WithDatabase(0) .WithEndpoint((rediscon.Split(':')[0]).ToSafeString(""), (rediscon.Split(':')[1]).ToSafeInt32(0)); }) .WithMaxRetries(1000) //尝试次数 .WithRetryTimeout(100) //尝试超时时间 .WithRedisBackplane("redis") //redis使用Back Plate .WithJsonSerializer() .WithRedisCacheHandle("redis", true); //redis缓存handle })); }
/// <summary> /// 检查是否配置了redis /// </summary> /// <returns></returns> public static bool CheckedRedisConsetting() { var rediscon = SystemJsonConfigManage.GetInstance().AppSettings["RedisCon"].ToSafeString(); return(string.IsNullOrEmpty(rediscon) ? false : true); }