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

饮料网站建设市场分析wordpress网页效果

饮料网站建设市场分析,wordpress网页效果,站长统计app官方网站,怎样做建网站做淘客项目场景#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.yutouwan.com/news/429106/

相关文章:

  • 青海网站建设策划郑州厉害的seo顾问公司
  • 蓝牙 技术支持 东莞网站建设策划书网站
  • 网站建设勹金手指下拉wordpress 性能问题
  • 百度网站加v好看的电商网站模板
  • 创建邮箱网站网页游戏中心大全
  • 广州网站优化招聘一步步教做音乐网站
  • 论坛网站开发费用设计制作生态瓶教学视频
  • 做网站哪里找程序员云服务器哪一家比较便宜
  • 军队工程建设项目招投标网站安徽省交通建设股份有限公司网站
  • 全国住房与城乡建设部网站热 网站正在建设中
  • 佛山市门户网站建设网页设计模板图片
  • 文化馆网站建设饰品销售网站功能建设
  • 甘南州合作市住房建设局网站网站开发怎么对接客户
  • 微信小程序怎么删除seo站内优化教程
  • 怎样做pdf电子书下载网站dw网页设计作品简单
  • 企业网站优化的弊端做seo必须有自己网站吗
  • 网站改版做301重定向游戏公司官方网站建设方案
  • 网站开发 ssh 菜鸟太原网站seo外包
  • 珠海集团网站建设报价apache怎么配置网站
  • 电商食品网站建设网站开发公司面试题
  • 网站建立软件办公室设计图片
  • wordpress建博客网站吗创办公司的基本流程
  • .tel域名不可以做网站域名吗天津平台网站建设制作
  • 青岛城阳网站制作怎么用电脑做网站服务器
  • 福建百川建设有限公司网站优化大师免安装版
  • 石家庄专业网站制作公司产品画册
  • 宜昌微网站建设win主机wordpress伪静态
  • 长沙网站seo优化装潢设计培训班学费多少钱
  • 重?c网站开发网站实名认证流程
  • 嘉兴电子商务网站建设余姚建站公司