十堰网站建设电话wordpress 登录地址
news/
2025/9/30 19:05:45/
文章来源:
十堰网站建设电话,wordpress 登录地址,ip域名查询网站入口,贵阳市建设局信息管理网站1.Hazelcast介绍 Hazelcast是Hazelcast公司开源的一款分布式内存数据库产品#xff0c;提供弹性可扩展、高性能的分布式内存计算。并通过提供诸如Map#xff0c;Queue#xff0c;ExecutorService#xff0c;Lock和JCache等Java的许多开发人员友好的分布式实现。 Hazelcast优… 1.Hazelcast介绍 Hazelcast是Hazelcast公司开源的一款分布式内存数据库产品提供弹性可扩展、高性能的分布式内存计算。并通过提供诸如MapQueueExecutorServiceLock和JCache等Java的许多开发人员友好的分布式实现。 Hazelcast优势 Hazelcast提供开源版本。Hazelcast无需安装只是个极小jar包。Hazelcast提供开箱即用的分布式数据结构如MapQueueMultiMapTopicLock和Executor。Hazelcast集群非传统主从关系避免了单点故障集群中所有成员共同分担集群功能。Hazelcast集群提供弹性扩展新成员在内存不足或负载过高时能动态加入集群。Hazelcast集群中成员分担数据缓存的同时互相冗余备份其他成员数据防止某成员离线后数据丢失。Hazelcast提供SPI接口支持用户自定义分布式数据结构。 Hazelcast适用场景 频繁读写数据需要高可用分布式缓存内存行NoSql存储分布式环境中弹性扩展 2.代码工程 pom.xml ?xml version1.0 encodingUTF-8?
project xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdparentartifactIdspringboot-demo/artifactIdgroupIdcom.et/groupIdversion1.0-SNAPSHOT/version/parentmodelVersion4.0.0/modelVersionartifactIdhazelcast/artifactIdpropertiesmaven.compiler.source8/maven.compiler.sourcemaven.compiler.target8/maven.compiler.target/propertiesdependenciesdependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-autoconfigure/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-test/artifactIdscopetest/scope/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-cache/artifactId/dependencydependencygroupIdcom.hazelcast/groupIdartifactIdhazelcast-all/artifactIdversion4.0.2/version/dependency/dependencies/project hazelcast.xml hazelcastxsi:schemaLocationhttp://www.hazelcast.com/schema/confighttp://www.hazelcast.com/schema/config/hazelcast-config-3.12.12.xsdxmlnshttp://www.hazelcast.com/schema/configxmlns:xsihttp://www.w3.org/2001/XMLSchema-instanceinstance-nameXML_Hazelcast_Instance/instance-namenetworkjoinmulticast enabledfalse/multicasttcp-ip enabledtruemember10.11.68.77/member/tcp-ip/join/network
/hazelcast application.yaml server:port: 8090 entity package com.et.hazelcast.entity;
import java.io.Serializable;
public class Employee implements Serializable{private static final long serialVersionUID 1L;private int empId;private String name;private String department;public Employee(Integer id, String name, String department) {super();this.empId id;this.name name;this.department department;}public int getEmpId() {return empId;}public void setEmpId(int empId) {this.empId empId;}public String getName() {return name;}public void setName(String name) {this.name name;}public String getDepartment() {return department;}public void setDepartment(String department) {this.department department;}Overridepublic String toString() {return Employee [empId empId , name name , department department ];}
} controller package com.et.hazelcast.controller;import com.et.hazelcast.entity.Employee;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;import java.util.HashMap;
import java.util.Map;Controller
public class HelloWorldController {RequestMapping(/hello)ResponseBodypublic MapString, Object showHelloWorld(){MapString, Object map new HashMap();map.put(msg, HelloWorld);return map;}Cacheable(value employee)GetMapping(employee/{id})ResponseBodypublic Employee getSubscriber(PathVariable(id) int id) throwsInterruptedException {System.out.println(Finding employee information with id id ...);return new Employee(id, John Smith, CS);}
} 准备三个启动类 package com.et.hazelcast;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;EnableCaching
SpringBootApplication
public class HazelcastNode1Starter {public static void main(String[] args) {SpringApplication.run(HazelcastNode1Starter.class, args);}} package com.et.hazelcast;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
EnableCaching
SpringBootApplication
public class HazelcastNode2Starter {public static void main(String[] args) {SpringApplication.run(HazelcastNode2Starter.class, args);}
} package com.et.hazelcast;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
EnableCaching
SpringBootApplication
public class HazelcastNode3Starter {public static void main(String[] args) {SpringApplication.run(HazelcastNode3Starter.class, args);}
} java代码客户端 这个代码中最关键的参数是需要设置之前定义的cluster-name “hazelcast-cluster”。 这样就实现了对hazelcast集群中map的调用。上述过程中如果关闭任意一个hazelcast节点上述缓存中的数据都可用。很好的实现了分布式。 package com.et.hazelcast;import com.hazelcast.client.HazelcastClient;
import com.hazelcast.client.config.ClientConfig;
import com.hazelcast.core.HazelcastInstance;
import lombok.extern.slf4j.Slf4j;import java.util.Map;Slf4j
public class HazelcastGetStartClient {public static void main(String[] args) {ClientConfig clientConfig new ClientConfig();clientConfig.setClusterName(hazelcast-cluster);HazelcastInstance instance HazelcastClient.newHazelcastClient(clientConfig);MapInteger, String clusterMap instance.getMap(map);}} 代码仓库 https://github.com/Harries/springboot-demo 3.测试 端口修改8088启动HazelcastNode1Starter端口修改8089启动HazelcastNode2Starter端口修改8090启动HazelcastNode3Starter Members {size:3, ver:5} [Member [10.11.68.77]:5701 - 2faf3b2d-76f3-493c-be48-d19d25aeb581 thisMember [10.11.68.77]:5702 - 63caca7f-f8ba-4b0a-989a-6e86a199fb72Member [10.11.68.77]:5703 - 3e9fa03c-72f4-4866-8904-73b908c4005d
] 浏览器输入http://localhost:8088/employee/6存入数据到hazelcast里面控制台输出 Finding employee information with id 6 ... 浏览器输入http://localhost:8089/employee/6可以直接获取缓存数据控制台不会打印日志出来 浏览器输入http://localhost:8090/employee/6可以直接获取缓存数据控制台不会打印日志出来 4.引用 http://element-ui.cn/news/show-552564.htmlhttp://www.liuhaihua.cn/archives/710310.html
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/923170.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!