文献: https://yanbin.blog/hazelcast-introduction/
- queue类型,点对点,只能一台机消费,可能要改配置,暂未知
- 客户端修改集群数据,文档说不能修改,现修改成功,暂未知
- 默认配置是什么样?
<!--hazelcast 缓存-->
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast</artifactId>
<version>3.11.4</version>
</dependency>
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast-client</artifactId>
<version>3.11.4</version>
</dependency>
package com.example.demojar.controller;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import java.util.List;
import java.util.Map;
import java.util.Queue;
public class HazelcastMaster {
public static void main(String[] args) {
//Map、Queue、MultiMap、Set、List、Semaphore、Atomic 等接口
HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance();
//创建map类型
Map<String, Object> myMap = hazelcastInstance.getMap("myMap");
myMap.put("key1","集群map");
//创建queue类型,点对点,只能一台机消费,可能要改配置,暂未知
Queue<Object> myQueue = hazelcastInstance.getQueue("myQueue");
myQueue.offer("Holle hazelcast");
myQueue.offer("Holle hazelcast queue");
//创建list类型
List<String> myList = hazelcastInstance.getList("myList");
myList.add("list类型数据1");
myList.add("list类型数据2");
myList.add("list类型数据3");
}
}
package com.example.demojar.controller;
import com.alibaba.fastjson.JSON;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import java.util.List;
import java.util.Map;
import java.util.Queue;
public class HazelcastSlave {
public static void main(String[] args) {
//创建一个 hazelcastInstance实例
HazelcastInstance instance = Hazelcast.newHazelcastInstance();
Map<String, Object> clusterMap = instance.getMap("myMap");
Queue<Object> clusterQueue = instance.getQueue("myQueue");
System.out.println("Map Value:" + clusterMap.get("key1"));
System.out.println("Queue Size :" + clusterQueue.size());
System.out.println("Queue Value 1:" + clusterQueue.poll());
System.out.println("Queue Value 2:" + clusterQueue.poll());
System.out.println("Queue Size :" + clusterQueue.size());
//获取list类型
List<String> myList = instance.getList("myList");
System.out.println(JSON.toJSONString(myList));
}
}
package com.example.demojar.controller;
import com.alibaba.fastjson.JSON;
import com.hazelcast.client.config.ClientConfig;
import com.hazelcast.core.HazelcastInstance;
import java.util.List;
import java.util.Map;
import java.util.Queue;
public class HazelcastClientDemo {
public static void main(String[] args) {
ClientConfig clientConfig = new ClientConfig();
HazelcastInstance instance = com.hazelcast.client.HazelcastClient.newHazelcastClient(clientConfig);
//获取map类型
Map<String, Object> clusterMap = instance.getMap("myMap");
//客户端修改集群数据,文档说不能修改,现修改成功暂未知
clusterMap.put("key1","客户端put数据");
//获取queue类型
Queue<String> clusterQueue = instance.getQueue("myQueue");
System.out.println("Map Value:" + clusterMap.get("key1"));
System.out.println("Queue Size :" + clusterQueue.size());
System.out.println("Queue Value 1:" + clusterQueue.poll());
System.out.println("Queue Value 2:" + clusterQueue.poll());
System.out.println("Queue Size :" + clusterQueue.size());
//获取list类型
List<String> myList = instance.getList("myList");
System.out.println(JSON.toJSONString(myList));
}
}