Chapter 12. Configuration

Table of Contents

12.1. Creating Separate Clusters
12.2. Network Configuration
12.2.1. Configuring TCP/IP Cluster
12.2.2. Specifying Network Interfaces
12.2.3. EC2 Auto Discovery
12.2.4. Network Partitioning (Split-Brain Syndrome)
12.2.5. SSL
12.2.6. Encryption
12.2.7. Socket Interceptor
12.2.8. IPv6 Support
12.2.9. Restricting Outbound Ports
12.3. Partition Group Configuration
12.4. Listener Configurations
12.5. Wildcard Configuration
12.6. Advanced Configuration Properties
12.7. Logging Configuration
12.8. Setting License Key (Enterprise Edition Only)

Hazelcast can be configured through xml or using configuration api or even mix of both.

  1. Xml Configuration

    If you are using default Hazelcast instance (Hazelcast.getDefaultInstance()) or creating new Hazelcast instance with passing null parameter (Hazelcast.newHazelcastInstance(null)), Hazelcast will look into two places for the configuration file:

    • System property: Hazelcast will first check if "hazelcast.config" system property is set to a file path. Example: -Dhazelcast.config=C:/myhazelcast.xml.

    • Classpath: If config file is not set as a system property, Hazelcast will check classpath for hazelcast.xml file.

    If Hazelcast doesn't find any config file, it will happily start with default configuration (hazelcast-default.xml) located in hazelcast.jar. (Before configuring Hazelcast, please try to work with default configuration to see if it works for you. Default should be just fine for most of the users. If not, then consider custom configuration for your environment.)

    If you want to specify your own configuration file to create Config, Hazelcast supports several ways including filesystem, classpath, InputStream, URL etc.:

    • Config cfg = new XmlConfigBuilder(xmlFileName).build();

    • Config cfg = new XmlConfigBuilder(inputStream).build();

    • Config cfg = new ClasspathXmlConfig(xmlFileName);

    • Config cfg = new FileSystemXmlConfig(configFilename);

    • Config cfg = new UrlXmlConfig(url);

    • Config cfg = new InMemoryXmlConfig(xml);

  2. Programmatic Configuration

    To configure Hazelcast programatically, just instantiate a Config object and set/change its properties/attributes due to your needs.

    Config cfg = new Config();
    cfg.setPort(5900);
    cfg.setPortAutoIncrement(false);
            
    NetworkConfig network = cfg.getNetworkConfig();
    Join join = network.getJoin();
    join.getMulticastConfig().setEnabled(false);
    join.getTcpIpConfig().addMember("10.45.67.32").addMember("10.45.67.100")
                .setRequiredMember("192.168.10.100").setEnabled(true);
    network.getInterfaces().setEnabled(true).addInterface("10.45.67.*");
            
    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);

After creating Config object, you can use it to initialize default Hazelcast instance or create a new Hazelcast instance.

HazelcastInstance with a name:

12.1. Creating Separate Clusters

By specifying group-name and group-password, you can separate your clusters in a simple way; dev group, production group, test group, app-a group etc...

<hazelcast>
    <group>
        <name>dev</name>
        <password>dev-pass</password>
    </group>
    ...
</hazelcast>

You can also set the groupName with Config API. JVM can host multiple Hazelcast instances (nodes). Each node can only participate in one group and it only joins to its own group, does not mess with others. Following code creates 3 separate Hazelcast nodes, h1 belongs to app1 cluster, while h2 and h3 are belong to app2 cluster.

Config configApp1 = new Config();
configApp1.getGroupConfig().setName("app1");

Config configApp2 = new Config();
configApp2.getGroupConfig().setName("app2");

HazelcastInstance h1 = Hazelcast.newHazelcastInstance(configApp1);
HazelcastInstance h2 = Hazelcast.newHazelcastInstance(configApp2);
HazelcastInstance h3 = Hazelcast.newHazelcastInstance(configApp2);