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

廊坊哪里有做阿里巴巴网站的杭州网站建设洛洛科技

廊坊哪里有做阿里巴巴网站的,杭州网站建设洛洛科技,红河州网站建设,图书馆网站建设的要求在上一篇在SpringBoot中使用EhCache缓存#xff0c;我们完成了在Spring Boot中完成了对EhCaChe的使用#xff0c;这篇#xff0c;我们将对EhCache的进一步了解#xff0c;也就是搭建一个EhCache的缓存集群。 集群 在搭建一个EhCache的时候#xff0c;我们需要先了解我们完成了在Spring Boot中完成了对EhCaChe的使用这篇我们将对EhCache的进一步了解也就是搭建一个EhCache的缓存集群。 集群 在搭建一个EhCache的时候我们需要先了解什么是集群集群具有的特点 什么是集群以及集群的特点 集群是值将多个独立的计算机节点连接在一起通过网络协议协同工作用以实现工共同的目标在集群中各个节点通过通信和协作来提供更高的性能可用性和可扩展性。 集群可以用于各种不同领域和应用场景包括计算、存储、数据库、网络服务等通过将各个节点组成集群可以实现以下特点或者成为好处 高性能 集群可以将任务分配给不同的节点并行处理从而进一步提高整体的计算能力和处理速度通过增加节点的数量可以进一步提高集群的性能。高可用性集群中的节点可以相互备份和冗余当某个节点发生故障时其他节点可以接管其工作保证系统的持续可用性。这种冗余机制可以提高系统的容错能力。可扩展性通过向集群中添加新的节点可以轻松的拓展系统的处理能力和存储容量这种可拓展性可以使得集群能够应对不同增长的需求和负载。负载均衡集群可以通过负载均衡算法将请求分发到不同节点上从而平衡各个节点的负载避免单个节点过载提高系统的稳定性和性能。故障恢复集群可以通过故障检测和自动恢复机制来处理节点故障当某个节点发生故障的时候集群可以自动将任务重新分配给其他正常工作的节点从而实现故障的快速恢复。 集群demo的搭建 引入相关依赖 dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-data-jpa/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-cache/artifactId/dependencydependencygroupIdnet.sf.ehcache/groupIdartifactIdehcache/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-actuator/artifactId/dependencydependencygroupIdmysql/groupIdartifactIdmysql-connector-java/artifactId/dependencydependencygroupIdorg.projectlombok/groupIdartifactIdlombok/artifactIdscopeprovided/scope/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-test/artifactIdscopetest/scope/dependencyapplication.properties配置文件 spring.datasource.urljdbc:mysql://localhost:3306/test?useUnicodetruecharacterEncodingutf-8useSSLtrueserverTimezoneUTC spring.datasource.usernameroot spring.datasource.password123456 spring.datasource.driver-class-namecom.mysql.cj.jdbc.Driverspring.jpa.show-sqltrue spring.jpa.hibernate.ddl-autocreate#logging.level.net.sf.ehcachedebug# 不同实例的配置 #spring.cache.ehcache.configclasspath:ehcache-1.xml #spring.cache.ehcache.configclasspath:ehcache-2.xml# 用不同命令启动不同实例 #-Dserver.port8001 -Dspring.cache.ehcache.configclasspath:ehcache-1.xml #-Dserver.port8002 -Dspring.cache.ehcache.configclasspath:ehcache-2.xml 创建一个User实体类 Entity public class User implements Serializable {IdGeneratedValueprivate Long id;private String name;private Integer age;public User(String name, Integer age) {this.name name;this.age age;}public Long getId() {return id;}public void setId(Long id) {this.id id;}public String getName() {return name;}public void setName(String name) {this.name name;}public Integer getAge() {return age;}public void setAge(Integer age) {this.age age;}public User() {} }创建一个User实体的数据访问实现 //插入缓存注解 CacheConfig(cacheNames users) public interface UserRepository extends JpaRepositoryUser, Long {CacheableUser findByName(String name); }在resources目录下分别创建ehcache-1.xml ehcache xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:noNamespaceSchemaLocationehcache.xsd!--这里的users对应我们常用的--cache nameusersmaxEntriesLocalHeap200timeToLiveSeconds600cacheEventListenerFactoryclassnet.sf.ehcache.distribution.RMICacheReplicatorFactorypropertiesreplicateAsynchronouslytrue,replicatePutstrue,replicateUpdatestrue,replicateUpdatesViaCopyfalse,replicateRemovalstrue //cachecacheManagerPeerProviderFactoryclassnet.sf.ehcache.distribution.RMICacheManagerPeerProviderFactorypropertieshostName10.10.0.100,port40001,socketTimeoutMillis2000,peerDiscoverymanual,rmiUrls//10.10.0.101:40001/users //ehcache 创建另一个ehcache-2.xml ehcache xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:noNamespaceSchemaLocationehcache.xsdcache nameusersmaxEntriesLocalHeap200timeToLiveSeconds600cacheEventListenerFactoryclassnet.sf.ehcache.distribution.RMICacheReplicatorFactorypropertiesreplicateAsynchronouslytrue,replicatePutstrue,replicateUpdatestrue,replicateUpdatesViaCopyfalse,replicateRemovalstrue //cachecacheManagerPeerProviderFactoryclassnet.sf.ehcache.distribution.RMICacheManagerPeerProviderFactorypropertieshostName10.10.0.101,port40001,socketTimeoutMillis2000,peerDiscoverymanual,rmiUrls//10.10.0.100:40001/users //ehcache cache标签中定义名为users的缓存这里我们增加了一个子标签定义cacheEventListenerFactory这个标签主要用来定义缓存事件监听的处理策略它有以下这些参数用来设置缓存的同步策略 replicatePuts当一个新元素增加到缓存中的时候是否要复制到其他的peers。默认是true。 replicateUpdates当一个已经在缓存中存在的元素被覆盖时是否要进行复制。默认是true。 replicateRemovals当元素移除的时候是否进行复制。默认是true。 replicateAsynchronously复制方式是异步的指定为true时还是同步的指定为false时。默认是true。 replicatePutsViaCopy当一个新增元素被拷贝到其他的cache中时是否进行复制指定为true时为复制默认是true。 replicateUpdatesViaCopy当一个元素被拷贝到其他的cache中时是否进行复制指定为true时为复制默认是true。 新增了一个cacheManagerPeerProviderFactory标签的配置用来指定组建的集群信息和要同步的缓存信息其中 hostName是当前实例的主机名 port当前实例用来同步缓存的端口号 socketTimeoutMillis同步缓存的Socket超时时间 peerDiscovery集群节点的发现模式有手工与自动两种这里采用了手工指定的方式 rmiUrls当peerDiscovery设置为manual的时候用来指定需要同步的缓存节点如果存在多个用|连接 注意以上ip地址的分配 ok具体的配置我们已经配置完毕了那么我们启动项目和添加测试类进行测试了 EnableCaching SpringBootApplication public class Application {public static void main(String[] args) throws Exception { // LocateRegistry.createRegistry(Integer.valueOf(System.getProperty(rmi.port)));SpringApplication.run(Application.class, args);}RestControllerstatic class HelloController {Autowiredprivate UserRepository userRepository;GetMapping(/create)public void create() {userRepository.save(new User(AAA, 10));}GetMapping(/update)public User update() {User u1 userRepository.findByName(AAA);u1.setAge(20);u1 userRepository.save(u1);return u1;}GetMapping(/find)public User find() {User u1 userRepository.findByName(AAA);System.out.println(查询AAA用户 u1.getAge());return u1;}} }我们通过打包的方式运行我们的实例 # 实例1 -Dspring.cache.ehcache.configclasspath:ehcache-1.xml # 实例2 -Dspring.cache.ehcache.configclasspath:ehcache-2.xml在以上代码中也就是我们常用的Controller层主要围绕我们所说的命令参数启动相关实例。 调用实例1的/create接口创建一条数据 调用实例1的/find接口此时会清除缓存中的User,同时同步缓存相关信息给另一个实例在实例1中会存在我们常用的SQL语句。 调用实例2的/find接口由于缓存集群同步了User的信息所以在实例2中的这次查询也不会出现SQL语句 以及创建一个测试类 Slf4j RunWith(SpringRunner.class) SpringBootTest public class ApplicationTests {Autowiredprivate UserRepository userRepository;Autowiredprivate CacheManager cacheManager;Testpublic void test() throws Exception {System.out.println(CacheManager type : cacheManager.getClass());// 创建1条记录userRepository.save(new User(AAA, 10));User u1 userRepository.findByName(AAA);System.out.println(第一次查询 u1.getAge());User u2 userRepository.findByName(AAA);System.out.println(第二次查询 u2.getAge());} }注意以上实例建议在多机的情况下进行有云服务器就是使用云服务器并配备好上述的Ip地址方便集群之间进行通讯通过打包的方式运行可以帮助我们减少很多麻烦
http://www.hkea.cn/news/14456456/

相关文章:

  • 什么是网站建设外包wordpress添加项目
  • 兰州市建设工程招标投标中心网站产品推广宣传语
  • 更新网站要怎么做呢做国外贸易的网站
  • 展览公司网站建设中国城乡建设部网站证书查询
  • 做淘宝浏览单的网站前端做网站需要学什么
  • 信诚网络公司网站小程序公众号网站开发
  • 做网站时遇到的问题网站开发的业务需求分析
  • 盐城做百度网站搭建网站团队计划
  • 网站的中英文切换代码网站页面相似度检测
  • 南昌定制网站开发费用网站设计工程师
  • 常德做网站报价公司做网站都咨询哪些问题
  • 做宠物商品的网站怎么做网站
  • 企业网站宽度给多少漳州网站优化
  • vultr做网站做图片网站侵权吗
  • 怎么做网站信息留下自己的wordpress
  • 网站热力图工具泉州制作网站公司
  • 西部数码网站建设软件开发各阶段工作量比例
  • cms做的电影网站中国世界排名变化
  • 网站的系统建设方式有经验的高密网站建设
  • 网站开发流程指什么订阅号怎么做网站
  • 天津市建设监理协会网站锦州网站建设信息
  • 做短连接的网站修改wordpress登录框
  • wordpress 中文网站一元购网站建设流程
  • 乐达网站建设怎么自己做网站服务器
  • 怎样给自己的网站做优化哈尔滨seo网站管理
  • 网站做系统叫什么济南哪个网络公司建网站好
  • 开发一个网站的步骤流程门户网站改版方案
  • 网站数据库连接不上的常见问题wordpress page links to
  • 做调查问卷的网站百度云虚拟主机搭建wordpress
  • 网站建设ftp软件有哪些网页设计学校官网代码