【发布时间】:2018-12-19 23:17:50
【问题描述】:
我有一个 hazelcast 集群,在三个节点上运行,具有以下配置(使用 ansible 和 docker 进行部署):
hazelcast_cluster_login: "login"
hazelcast_cluster_password: "password"
hazelcast_maps: <map name="my_map"><backup-count>1</backup-count>
<time-to-live-seconds>3600</time-to-live-seconds></map>
以及下面的 Spring 配置
@Configuration
@EnableCaching
public class CacheConfig {
@Autowired
private HazelcastProperties properties;
@Bean
public HazelcastInstance getConfig() {
log.info("Connecting to Hazelcast on {} with login = {}",
properties.getHosts(),
properties.getLogin());
ClientConfig clientConfig = new ClientConfig();
clientConfig.getGroupConfig()
.setName(properties.getLogin())
.setPassword(properties.getPassword());
clientConfig.getNetworkConfig()
.setAddresses(properties.getHosts())
.setConnectionAttemptLimit(0);
HazelcastInstance instance = HazelcastClient.newHazelcastClient(clientConfig);
return instance;
}
@Bean
public CacheManager hazelcastCacheManager(HazelcastInstance
hazelcastInstance) {
return new HazelcastCacheManager(hazelcastInstance);
}
}
此代码能够成功连接和授权。
在我的应用程序中使用my_map Map 和@Cacheable 的正确方法是什么?使用@Cacheable("my_map") 是否正确(找不到诊断方法,这张地图是否为空)?
附言尝试使用 config.addMapConfig(...) 进行配置,但这不适用于正在运行的集群。
【问题讨论】: