Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
518 views
in Technique[技术] by (71.8m points)

java - HazelCast Programmatic Configuration of Tcp-IP is no adding members in cluster

Below is the HazelCast Programmatic Configuration given in Documentation but it is unable to add members in HazelCast Cluster.

    Config cfg = new Config();
    Hazelcast.newHazelcastInstance(cfg);

    cfg.setProperty("hazelcast.initial.min.cluster.size","3"); 
    cfg.getGroupConfig().setName("DEV").setPassword("DEV-pass");
    NetworkConfig network = cfg.getNetworkConfig();
    JoinConfig join = network.getJoin();
    TcpIpConfig tcpipConfig=join.getTcpIpConfig();
    tcpipConfig.addMember("172.17.153.87").addMember("10.45.67.100")
    .setRequiredMember("192.168.10.100").setEnabled(true);
    network.getInterfaces().setEnabled(true).addInterface("10.45.67.*");
     System.out.println(tcpipConfig.isEnabled());
     System.out.println(tcpipConfig.getMembers());

    MapConfig mapCfg = new MapConfig();
    mapCfg.setName("testMap");
    mapCfg.setBackupCount(2);
    mapCfg.getMaxSizeConfig().setSize(10000);
    mapCfg.setTimeToLiveSeconds(300);

    MapStoreConfig mapStoreCfg = new MapStoreConfig();
    mapStoreCfg.setClassName("com.hazelcast.examples.DummyStore").setEnabled(true);
    mapCfg.setMapStoreConfig(mapStoreCfg);

    NearCacheConfig nearCacheConfig = new NearCacheConfig();
    nearCacheConfig.setMaxSize(1000).setMaxIdleSeconds(120).setTimeToLiveSeconds(300);
    mapCfg.setNearCacheConfig(nearCacheConfig);

    cfg.addMapConfig(mapCfg);

please look at the code and let me if any thing further modification is required to add members to hazelcast cluster

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Add this line to turn off multicast in favour of TCP,

join.getMulticastConfig().setEnabled(false);

Move this line to the end,

Hazelcast.newHazelcastInstance(cfg);

You should finish the config before building the instance.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...