HazelCast Programmatic Configuration of Tcp-IP is no adding members in cluster
Asked Answered
A

2

1

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

Antinode answered 3/1, 2017 at 22:24 Comment(0)
K
3

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.

Knocker answered 3/1, 2017 at 23:3 Comment(0)
F
0

Under Windows, the out-of-the-box configuration of Hazelcast (with empty Config) just worked.
I just had to start my Java program multiple times in parallel and the Hazelcast nodes discovered each other.

Under Linux, it was more tricky: the following is a working example - just run multiple instances of it in parallel.

import java.util.*;
import com.hazelcast.config.*;
import com.hazelcast.core.*;

public class NewClass {

    public static void main(String[] args) {
        Config config = new Config();
        config.getNetworkConfig().setPublicAddress("127.0.0.1")
                .setPort(7771).setPortAutoIncrement(true);
        JoinConfig join = config.getNetworkConfig().getJoin();
        join.getMulticastConfig().setEnabled(false);
        join.getAwsConfig().setEnabled(false);
        join.getTcpIpConfig().setEnabled(true).setMembers(
                Arrays.asList(
                    "127.0.0.1:7771",
                    "127.0.0.1:7772",
                    "127.0.0.1:7773"));

        HazelcastInstance h = Hazelcast.newHazelcastInstance(config);
    }
}

Output after third execution:

[snip]

Members [3] {
    Member [127.0.0.1]:7771 - 18f5aada-6f00-4077-814e-337517d5c1eb
    Member [127.0.0.1]:7772 - e9e2e7fd-e2fe-4c56-80c5-6b499d07b2b9
    Member [127.0.0.1]:7773 - 14fd377c-69fd-4c69-a9b8-086dd1cd7857 this
}

[snip]
Filly answered 17/8, 2017 at 21:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.