Hazelcast忽略了群集配置

时间:2016-02-23 14:43:05

标签: hazelcast

我定义了“静态”hazelcast配置:

@Bean
    public Config getHazelcastConfig() {
        final Config config = new Config();
        config.setProperty("hazelcast.logging.type", "slf4j");
        final GroupConfig groupConfig = new GroupConfig();
        groupConfig.setName("projectName");
        groupConfig.setPassword("projectPassword");
        config.setGroupConfig(groupConfig);
        final NetworkConfig networkConfig = new NetworkConfig();
        final TcpIpConfig tcpIpConfig = new TcpIpConfig();
        final String[] members = "10.0.0.2".split(",");
        for (String member : members) {
            tcpIpConfig.addMember(member);
        }
        tcpIpConfig.setConnectionTimeoutSeconds(5);
        final JoinConfig joinConfig = networkConfig.getJoin();
        joinConfig.getAwsConfig().setEnabled(false);
        joinConfig.getMulticastConfig().setEnabled(false);
        joinConfig.setTcpIpConfig(tcpIpConfig);
        joinConfig.getTcpIpConfig().setEnabled(true);
        joinConfig.getTcpIpConfig().setConnectionTimeoutSeconds(5);
        config.setNetworkConfig(networkConfig);
        config.setInstanceName("projectInstanceName");
        return config;
    }

其中“10.0.0.2”是我的localhost ip。我只想在我的tcpIpConfig成员中添加一个hazelcast实例。我的朋友坐在同一个网络中,IP号码为“10.0.0.3”。他懒得在git上共享的属性文件中更改密码和组名,并且正在连接到我的集群。为什么他能够连接到我的集群?我怎么能阻止这个?

1 个答案:

答案 0 :(得分:0)

Yesss,@ Sachin。你是对的。添加后

securityCfg.setEnabled(true);

检查hazelcast配置密码和登录。

我在localhost上使用多个hazelcast实例的第二个问题与hibernate有关。在haibernate中使用hazelcast作为二级缓存时,会创建hazelcast成员。它可以通过以下方式打开/关闭:

properties.setProperty("hibernate.cache.hazelcast.use_native_client", "false");

properties.setProperty("hibernate.cache.hazelcast.use_native_client", "true");