当前位置: 首页 > news >正文

搜索建站网亚马逊欧洲站vat怎么申请

搜索建站网,亚马逊欧洲站vat怎么申请,沧州营销软件,价格划算的做pc端网站项目场景#xff1a; Spring Boot集成Redis集群#xff0c;使用lettuce连接Cluster集群实例。 问题描述 redis其中一个节点挂了之后#xff0c;springboot集成redis集群配置信息没有及时刷新#xff0c;出现读取操作报错。 java.lang.IllegalArgumentException: Connec…项目场景 Spring Boot集成Redis集群使用lettuce连接Cluster集群实例。 问题描述 redis其中一个节点挂了之后springboot集成redis集群配置信息没有及时刷新出现读取操作报错。 java.lang.IllegalArgumentException: Connection to 127.0.0.1:6379 not allowed. This connection point is not known in the cluster view exceptionStackTrace io.lettuce.core.cluster.PooledClusterConnectionProvider.getConnectionAsync(PooledClusterConnectionProvider.java:359) io.lettuce.core.cluster.ClusterDistributionChannelWriter.write(ClusterDistributionChannelWriter.java:93) io.lettuce.core.cluster.ClusterCommand.complete(ClusterCommand.java:56) io.lettuce.core.protocol.CommandHandler.decode(CommandHandler.java:563) io.lettuce.core.protocol.CommandHandler.channelRead(CommandHandler.java:516)原因分析 lettuce默认是没有开始拓扑更新及读写分离导致的 解决方案 这里分为几种情况 springboot 1.x之前版本默认使用jedis无需要手动开启刷新springboot 2.x默认为Lettuce需要代码设置开启刷新节点拓扑策略springboot 2.3.0开始支持集群拓扑刷新功能属性配置开启即可 第一种情况springboot1.x版本环境 springboot1.x之前版本默认使用jedis无需手动开启动态刷新。 第二种情况springboot2.0~2.3版本环境 springboot2.0-2.3版本默认使用lettuce默认不支持属性配置集群拓扑刷新。使用lettuce需要增加配置类需要手动开启刷新。 配置类如下 package com.test.config;import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.annotation.PropertyAccessor; import com.fasterxml.jackson.databind.ObjectMapper; import io.lettuce.core.cluster.ClusterClientOptions; import io.lettuce.core.cluster.ClusterTopologyRefreshOptions; import lombok.extern.java.Log; import org.apache.commons.pool2.impl.GenericObjectPoolConfig; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.data.redis.RedisProperties; import org.springframework.cache.annotation.EnableCaching; import org.springframework.cache.interceptor.KeyGenerator; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.redis.connection.RedisClusterConfiguration; import org.springframework.data.redis.connection.RedisStandaloneConfiguration; import org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration; import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; import org.springframework.data.redis.connection.lettuce.LettucePoolingClientConfiguration; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; import org.springframework.data.redis.serializer.RedisSerializer; import org.springframework.data.redis.serializer.StringRedisSerializer;import java.lang.reflect.Method; import java.time.Duration;Log Configuration EnableCaching // 开启缓存支持 public class RedisConfig {Autowiredprivate RedisProperties redisProperties;Bean(destroyMethod destroy) //销毁这个bean之前调用这个destroy回调方法释放资源public LettuceConnectionFactory redisConnectionFactory() {// redis单节点if (null redisProperties.getCluster() || null redisProperties.getCluster().getNodes()) {RedisStandaloneConfiguration configuration new RedisStandaloneConfiguration(redisProperties.getHost(),redisProperties.getPort());configuration.setPassword(redisProperties.getPassword()); //RedisPassword.of(redisProperties.getPassword())configuration.setDatabase(redisProperties.getDatabase());return new LettuceConnectionFactory(configuration);}// redis集群RedisClusterConfiguration redisClusterConfiguration new RedisClusterConfiguration(redisProperties.getCluster().getNodes());redisClusterConfiguration.setPassword(redisProperties.getPassword()); //RedisPassword.of(redisProperties.getPassword())redisClusterConfiguration.setMaxRedirects(redisProperties.getCluster().getMaxRedirects());GenericObjectPoolConfig genericObjectPoolConfig new GenericObjectPoolConfig();genericObjectPoolConfig.setMaxTotal(redisProperties.getLettuce().getPool().getMaxActive());genericObjectPoolConfig.setMaxIdle(redisProperties.getLettuce().getPool().getMaxIdle());genericObjectPoolConfig.setMinIdle(redisProperties.getLettuce().getPool().getMinIdle());genericObjectPoolConfig.setMaxWaitMillis(redisProperties.getLettuce().getPool().getMaxWait().getSeconds());// 支持自适应集群拓扑刷新和动态刷新源ClusterTopologyRefreshOptions clusterTopologyRefreshOptions ClusterTopologyRefreshOptions.builder().enableAllAdaptiveRefreshTriggers()// 开启自适应刷新.enableAdaptiveRefreshTrigger()// 开启定时刷新.enablePeriodicRefresh(Duration.ofSeconds(5)).build();ClusterClientOptions clusterClientOptions ClusterClientOptions.builder().topologyRefreshOptions(clusterTopologyRefreshOptions).build();LettuceClientConfiguration lettuceClientConfiguration LettucePoolingClientConfiguration.builder().poolConfig(genericObjectPoolConfig) //如果使用默认配置可以注释genericObjectPoolConfig // .readFrom(ReadFrom.SLAVE_PREFERRED) //读写分离主写从读模式配置.clientOptions(clusterClientOptions).build();LettuceConnectionFactory lettuceConnectionFactory new LettuceConnectionFactory(redisClusterConfiguration, lettuceClientConfiguration);lettuceConnectionFactory.setShareNativeConnection(false);// 是否允许多个线程操作共用同一个缓存连接默认 truefalse 时每个操作都将开辟新的连接lettuceConnectionFactory.resetConnection();// 重置底层共享连接, 在接下来的访问时初始化return lettuceConnectionFactory;}/*** RedisTemplate配置*/Beanpublic RedisTemplateObject, Object redisTemplate(LettuceConnectionFactory factory) {RedisTemplateObject, Object redisTemplate new RedisTemplate();redisTemplate.setConnectionFactory(factory);// 使用注解Bean返回RedisTemplate的时候同时配置hashkey和hashValue的序列虎方式// key采用String的序列化方式redisTemplate.setKeySerializer(keySerializer());// value使用jackson序列化方式redisTemplate.setValueSerializer(valueSerializer());// hash的key采用String的序列化方式redisTemplate.setHashKeySerializer(keySerializer());// hash的value使用jackson序列化方式redisTemplate.setHashValueSerializer(valueSerializer());/**必须执行这个函数,初始化RedisTemplate*/// 需要先调用afterPropertiesSet方法,此方法是应该是初始化参数和初始化工作。redisTemplate.afterPropertiesSet();log.info(序列化完成);return redisTemplate;}Beanpublic KeyGenerator keyGenerator() {return new KeyGenerator() {Overridepublic Object generate(Object target, Method method, Object... params) {StringBuffer sb new StringBuffer();sb.append(target.getClass().getName());sb.append(method.getName());for (Object obj : params) {sb.append(obj.toString());}return sb.toString();}};}/*** key键序列化方式** return RedisSerializer*/private RedisSerializerString keySerializer() {return new StringRedisSerializer();}/*** value值序列化方式** return*/private Jackson2JsonRedisSerializer valueSerializer() {Jackson2JsonRedisSerializer jackson2JsonRedisSerializer new Jackson2JsonRedisSerializer(Object.class);ObjectMapper om new ObjectMapper();om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);jackson2JsonRedisSerializer.setObjectMapper(om);return jackson2JsonRedisSerializer;} }配置文件 #Redis Configuration spring.redis.cluster.max-redirects10 spring.redis.cluster.nodes127.0.0.1:8001,127.0.0.1:8002 spring.redis.timeout60000ms spring.redis.password spring.redis.lettuce.pool.max-active10 spring.redis.lettuce.pool.max-idle8 spring.redis.lettuce.pool.min-idle0 spring.redis.lettuce.pool.max-wait-1ms 注意注入LettuceConnectionFactory后一定要记得注入RedisTemplate并 redisTemplate.setConnectionFactory(factory); apache commons-pool2 包提供了一个通用的对象池技术的实现。可以很方便的基于它来实现自己的对象池比如 DBCP 和 Jedis 他们的内部对象池的实现就是依赖于 commons-pool2 。 dependencygroupIdorg.apache.commons/groupIdartifactIdcommons-pool2/artifactIdversion2.8.0/version /dependency第三种情况springboot2.3之后版本环境 springboot2.3之后版本默认使用lettuce默认支持属性配置开启集群拓扑刷新其解决方案属性配置开启即可。 spring.redis.lettuce.cluster.refresh.adaptive true spring.redis.lettuce.cluster.refresh.period30000 # 30秒自动刷新一次 关联文章Spring Boot集成Redis集群报错UnsupportedOperationException-CSDN博客
http://www.hkea.cn/news/14370862/

相关文章:

  • 免费网页制作网站建设永久免费windows xp
  • 湛江网站建设方案优化苏州做网站优化公司哪家好
  • 太原网站建设公司科学家做实验的网站
  • 做书网站 时光打开网站建设中是什么意思
  • 学习网站建设有前景没沈阳做网站的互联网公司
  • 天河低价网站建设phpok企业建站系统
  • 做网站的协议怎么加入平台卖货
  • 我们做网站 出教材 办育心经网络公司网络营销推广方案
  • 整站优化要多少钱网站建设与管理认识
  • 网站建设 作用佛山网站建设方案书
  • 一条龙建设网站惠州网站制作公司
  • 试分析网站推广和优化的原因爬虫 wordpress
  • 贺州招聘网站建设做网站空间需要多大
  • 海外打开网站慢网站建立服务
  • 免费的写作网站wordpress go
  • 网站开发免费网站改版需要注意
  • 个人做房产网站有哪些资料酒泉网站建设有哪些
  • 个人做网站平台互联科技 行业网站
  • 家政网站设计一个备案号多个网站
  • wordpress的企业网站服务器怎么做网站
  • 网站设计一年费用商丘做网站优化
  • .简述网站开发的流程网站制作怎么赚钱
  • 招远做网站案例重庆云阳网站建设
  • 北京网站建设厂家网站模板源码下载网
  • 网站百度权重怎么提升自媒体135的网站是多少
  • 做化工回收上什么网站用wordpress搭建网盘
  • 六盘水南宁网站建设公司取名字大全免费
  • 做外汇的人一般看什么网站网站网络营销推广制作
  • 怎么发现网站漏洞而做软件开发公司管理制度
  • 用dw设计网站模板下载地址北京商城开发