or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

cluster-management.mdconfiguration.mdcore-api.mddata-structures.mdindex.mdsql-service.mdstream-processing.md

configuration.mddocs/

0

# Configuration

1

2

Hazelcast provides a comprehensive configuration system that supports programmatic configuration, XML files, YAML files, and environment variables. The configuration system is hierarchical and allows fine-grained control over all aspects of cluster behavior.

3

4

## Main Configuration Classes

5

6

### Config Class

7

8

The main configuration class for Hazelcast server instances.

9

10

```java { .api }

11

import com.hazelcast.config.Config;

12

import com.hazelcast.config.NetworkConfig;

13

import com.hazelcast.config.MapConfig;

14

import com.hazelcast.config.QueueConfig;

15

import com.hazelcast.config.SerializationConfig;

16

import com.hazelcast.config.SecurityConfig;

17

import java.util.Map;

18

import java.util.Properties;

19

20

public class Config {

21

// Instance and cluster identification

22

public Config setInstanceName(String instanceName);

23

public String getInstanceName();

24

25

public Config setClusterName(String clusterName);

26

public String getClusterName();

27

28

// Network configuration

29

public NetworkConfig getNetworkConfig();

30

public Config setNetworkConfig(NetworkConfig networkConfig);

31

32

// Data structure configurations

33

public Map<String, MapConfig> getMapConfigs();

34

public Config addMapConfig(MapConfig mapConfig);

35

public MapConfig getMapConfig(String name);

36

37

public Map<String, QueueConfig> getQueueConfigs();

38

public Config addQueueConfig(QueueConfig queueConfig);

39

public QueueConfig getQueueConfig(String name);

40

41

// Advanced configurations

42

public SerializationConfig getSerializationConfig();

43

public Config setSerializationConfig(SerializationConfig serializationConfig);

44

45

public SecurityConfig getSecurityConfig();

46

public Config setSecurityConfig(SecurityConfig securityConfig);

47

48

// Properties and system properties

49

public Properties getProperties();

50

public Config setProperties(Properties properties);

51

public Config setProperty(String name, String value);

52

public String getProperty(String name);

53

54

// License key

55

public Config setLicenseKey(String licenseKey);

56

public String getLicenseKey();

57

58

// User context

59

public ConcurrentMap<String, Object> getUserContext();

60

61

// Configuration loading

62

public static Config load();

63

public static Config loadFromFile(File configurationFile);

64

public static Config loadFromStream(InputStream inputStream);

65

}

66

```

67

68

### ClientConfig Class

69

70

Configuration for Hazelcast client instances.

71

72

```java { .api }

73

import com.hazelcast.client.config.ClientConfig;

74

import com.hazelcast.client.config.ClientNetworkConfig;

75

import com.hazelcast.client.config.ClientSecurityConfig;

76

import com.hazelcast.client.config.ClientConnectionStrategyConfig;

77

78

public class ClientConfig {

79

// Instance identification

80

public ClientConfig setInstanceName(String instanceName);

81

public String getInstanceName();

82

83

public ClientConfig setClusterName(String clusterName);

84

public String getClusterName();

85

86

// Network configuration

87

public ClientNetworkConfig getNetworkConfig();

88

public ClientConfig setNetworkConfig(ClientNetworkConfig networkConfig);

89

90

// Security configuration

91

public ClientSecurityConfig getSecurityConfig();

92

public ClientConfig setSecurityConfig(ClientSecurityConfig securityConfig);

93

94

// Connection strategy

95

public ClientConnectionStrategyConfig getConnectionStrategyConfig();

96

public ClientConfig setConnectionStrategyConfig(ClientConnectionStrategyConfig connectionStrategyConfig);

97

98

// Properties

99

public Properties getProperties();

100

public ClientConfig setProperties(Properties properties);

101

public ClientConfig setProperty(String name, String value);

102

103

// Labels (for client identification)

104

public Set<String> getLabels();

105

public ClientConfig setLabels(Set<String> labels);

106

public ClientConfig addLabel(String label);

107

108

// User context

109

public ConcurrentMap<String, Object> getUserContext();

110

}

111

```

112

113

## Basic Configuration Examples

114

115

### Programmatic Server Configuration

116

117

```java { .api }

118

Config config = new Config();

119

120

// Basic instance settings

121

config.setInstanceName("my-hazelcast-server");

122

config.setClusterName("production-cluster");

123

124

// Set properties

125

config.setProperty("hazelcast.logging.type", "slf4j");

126

config.setProperty("hazelcast.operation.call.timeout.millis", "30000");

127

128

// Create instance

129

HazelcastInstance hz = Hazelcast.newHazelcastInstance(config);

130

```

131

132

### Programmatic Client Configuration

133

134

```java { .api }

135

ClientConfig clientConfig = new ClientConfig();

136

137

// Basic client settings

138

clientConfig.setInstanceName("my-client");

139

clientConfig.setClusterName("production-cluster");

140

141

// Network settings

142

clientConfig.getNetworkConfig()

143

.addAddress("192.168.1.100:5701", "192.168.1.101:5701")

144

.setSmartRouting(true)

145

.setRedoOperation(true)

146

.setConnectionTimeout(5000);

147

148

// Labels for client identification

149

clientConfig.addLabel("web-server")

150

.addLabel("region:us-east-1");

151

152

// Create client

153

HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);

154

```

155

156

## Network Configuration

157

158

### NetworkConfig Class

159

160

Controls network behavior including ports, interfaces, and join mechanisms.

161

162

```java { .api }

163

import com.hazelcast.config.NetworkConfig;

164

import com.hazelcast.config.JoinConfig;

165

import com.hazelcast.config.InterfacesConfig;

166

import com.hazelcast.config.SocketInterceptorConfig;

167

import java.util.Collection;

168

169

public class NetworkConfig {

170

// Port configuration

171

public NetworkConfig setPort(int port);

172

public int getPort();

173

174

public NetworkConfig setPortAutoIncrement(boolean portAutoIncrement);

175

public boolean isPortAutoIncrement();

176

177

public NetworkConfig setPortCount(int portCount);

178

public int getPortCount();

179

180

// Network interfaces

181

public InterfacesConfig getInterfaces();

182

public NetworkConfig setInterfaces(InterfacesConfig interfaces);

183

184

// Join configuration

185

public JoinConfig getJoin();

186

public NetworkConfig setJoin(JoinConfig join);

187

188

// Public address (for cloud/NAT environments)

189

public NetworkConfig setPublicAddress(String publicAddress);

190

public String getPublicAddress();

191

192

// Socket options

193

public SocketInterceptorConfig getSocketInterceptorConfig();

194

public NetworkConfig setSocketInterceptorConfig(SocketInterceptorConfig socketInterceptorConfig);

195

196

// SSL/TLS

197

public SSLConfig getSSLConfig();

198

public NetworkConfig setSSLConfig(SSLConfig sslConfig);

199

}

200

```

201

202

### Join Configuration

203

204

```java { .api }

205

import com.hazelcast.config.JoinConfig;

206

import com.hazelcast.config.MulticastConfig;

207

import com.hazelcast.config.TcpIpConfig;

208

import com.hazelcast.config.AwsConfig;

209

210

public class JoinConfig {

211

// Multicast discovery

212

public MulticastConfig getMulticastConfig();

213

public JoinConfig setMulticastConfig(MulticastConfig multicastConfig);

214

215

// TCP/IP discovery

216

public TcpIpConfig getTcpIpConfig();

217

public JoinConfig setTcpIpConfig(TcpIpConfig tcpIpConfig);

218

219

// Cloud discovery

220

public AwsConfig getAwsConfig();

221

public JoinConfig setAwsConfig(AwsConfig awsConfig);

222

223

public GcpConfig getGcpConfig();

224

public JoinConfig setGcpConfig(GcpConfig gcpConfig);

225

226

public AzureConfig getAzureConfig();

227

public JoinConfig setAzureConfig(AzureConfig azureConfig);

228

229

public KubernetesConfig getKubernetesConfig();

230

public JoinConfig setKubernetesConfig(KubernetesConfig kubernetesConfig);

231

232

// Auto-detection

233

public DiscoveryConfig getDiscoveryConfig();

234

public JoinConfig setDiscoveryConfig(DiscoveryConfig discoveryConfig);

235

}

236

```

237

238

### Network Configuration Examples

239

240

```java { .api }

241

Config config = new Config();

242

NetworkConfig network = config.getNetworkConfig();

243

244

// Basic network settings

245

network.setPort(5701)

246

.setPortAutoIncrement(true)

247

.setPortCount(20);

248

249

// Interface restrictions

250

network.getInterfaces()

251

.setEnabled(true)

252

.addInterface("192.168.1.*")

253

.addInterface("10.0.0.*");

254

255

// TCP/IP cluster discovery

256

JoinConfig join = network.getJoin();

257

join.getMulticastConfig().setEnabled(false);

258

join.getTcpIpConfig()

259

.setEnabled(true)

260

.addMember("192.168.1.100")

261

.addMember("192.168.1.101")

262

.addMember("192.168.1.102");

263

264

// Public address for cloud environments

265

network.setPublicAddress("203.0.113.1:5701");

266

267

// AWS discovery

268

join.getAwsConfig()

269

.setEnabled(true)

270

.setProperty("access-key", "your-access-key")

271

.setProperty("secret-key", "your-secret-key")

272

.setProperty("region", "us-east-1")

273

.setProperty("tag-key", "hazelcast-cluster")

274

.setProperty("tag-value", "production");

275

276

// Kubernetes discovery

277

join.getKubernetesConfig()

278

.setEnabled(true)

279

.setProperty("namespace", "hazelcast")

280

.setProperty("service-name", "hazelcast-service");

281

```

282

283

## Data Structure Configuration

284

285

### Map Configuration

286

287

```java { .api }

288

import com.hazelcast.config.MapConfig;

289

import com.hazelcast.config.EvictionConfig;

290

import com.hazelcast.config.IndexConfig;

291

import com.hazelcast.config.MapStoreConfig;

292

import com.hazelcast.config.NearCacheConfig;

293

294

public class MapConfig {

295

// Basic settings

296

public MapConfig setName(String name);

297

public String getName();

298

299

// Backup configuration

300

public MapConfig setBackupCount(int backupCount);

301

public int getBackupCount();

302

303

public MapConfig setAsyncBackupCount(int asyncBackupCount);

304

public int getAsyncBackupCount();

305

306

// TTL and idle time

307

public MapConfig setTimeToLiveSeconds(int timeToLiveSeconds);

308

public int getTimeToLiveSeconds();

309

310

public MapConfig setMaxIdleSeconds(int maxIdleSeconds);

311

public int getMaxIdleSeconds();

312

313

// Eviction configuration

314

public EvictionConfig getEvictionConfig();

315

public MapConfig setEvictionConfig(EvictionConfig evictionConfig);

316

317

// Indexing

318

public List<IndexConfig> getIndexConfigs();

319

public MapConfig addIndexConfig(IndexConfig indexConfig);

320

321

// Map store (persistence)

322

public MapStoreConfig getMapStoreConfig();

323

public MapConfig setMapStoreConfig(MapStoreConfig mapStoreConfig);

324

325

// Near cache

326

public NearCacheConfig getNearCacheConfig();

327

public MapConfig setNearCacheConfig(NearCacheConfig nearCacheConfig);

328

329

// Read backup data

330

public MapConfig setReadBackupData(boolean readBackupData);

331

public boolean isReadBackupData();

332

333

// Statistics

334

public MapConfig setStatisticsEnabled(boolean statisticsEnabled);

335

public boolean isStatisticsEnabled();

336

}

337

```

338

339

### Map Configuration Examples

340

341

```java { .api }

342

Config config = new Config();

343

344

// User session map configuration

345

MapConfig sessionMapConfig = new MapConfig("user-sessions");

346

sessionMapConfig.setBackupCount(2)

347

.setTimeToLiveSeconds(1800) // 30 minutes

348

.setMaxIdleSeconds(600) // 10 minutes

349

.setStatisticsEnabled(true);

350

351

// Eviction configuration

352

EvictionConfig evictionConfig = new EvictionConfig();

353

evictionConfig.setEvictionPolicy(EvictionPolicy.LRU)

354

.setMaxSizePolicy(MaxSizePolicy.PER_NODE)

355

.setSize(10000);

356

sessionMapConfig.setEvictionConfig(evictionConfig);

357

358

config.addMapConfig(sessionMapConfig);

359

360

// Product catalog map with indexes

361

MapConfig productMapConfig = new MapConfig("products");

362

productMapConfig.setBackupCount(1)

363

.setReadBackupData(true);

364

365

// Add indexes for better query performance

366

productMapConfig.addIndexConfig(new IndexConfig(IndexType.HASH, "category"))

367

.addIndexConfig(new IndexConfig(IndexType.SORTED, "price"))

368

.addIndexConfig(new IndexConfig(IndexType.BITMAP, "inStock"));

369

370

config.addMapConfig(productMapConfig);

371

372

// Cache map with near cache

373

MapConfig cacheMapConfig = new MapConfig("cache");

374

cacheMapConfig.setBackupCount(0) // No backup for cache data

375

.setTimeToLiveSeconds(300); // 5 minutes

376

377

// Near cache configuration

378

NearCacheConfig nearCacheConfig = new NearCacheConfig();

379

nearCacheConfig.setTimeToLiveSeconds(60)

380

.setMaxIdleSeconds(30)

381

.setInvalidateOnChange(true)

382

.setCacheLocalEntries(true);

383

384

cacheMapConfig.setNearCacheConfig(nearCacheConfig);

385

config.addMapConfig(cacheMapConfig);

386

```

387

388

### Queue Configuration

389

390

```java { .api }

391

import com.hazelcast.config.QueueConfig;

392

393

public class QueueConfig {

394

// Basic settings

395

public QueueConfig setName(String name);

396

public String getName();

397

398

// Capacity

399

public QueueConfig setMaxSize(int maxSize);

400

public int getMaxSize();

401

402

// Backup configuration

403

public QueueConfig setBackupCount(int backupCount);

404

public int getBackupCount();

405

406

public QueueConfig setAsyncBackupCount(int asyncBackupCount);

407

public int getAsyncBackupCount();

408

409

// Empty queue TTL

410

public QueueConfig setEmptyQueueTtl(int emptyQueueTtl);

411

public int getEmptyQueueTtl();

412

413

// Statistics

414

public QueueConfig setStatisticsEnabled(boolean statisticsEnabled);

415

public boolean isStatisticsEnabled();

416

417

// Queue store

418

public QueueStoreConfig getQueueStoreConfig();

419

public QueueConfig setQueueStoreConfig(QueueStoreConfig queueStoreConfig);

420

}

421

```

422

423

### Queue Configuration Example

424

425

```java { .api }

426

// Task queue configuration

427

QueueConfig taskQueueConfig = new QueueConfig("task-queue");

428

taskQueueConfig.setMaxSize(50000)

429

.setBackupCount(1)

430

.setStatisticsEnabled(true)

431

.setEmptyQueueTtl(300); // Remove empty queue after 5 minutes

432

433

config.addQueueConfig(taskQueueConfig);

434

435

// Priority queue configuration

436

QueueConfig priorityQueueConfig = new QueueConfig("priority-tasks");

437

priorityQueueConfig.setMaxSize(10000)

438

.setBackupCount(2); // Higher backup for important tasks

439

440

config.addQueueConfig(priorityQueueConfig);

441

```

442

443

## Advanced Configuration

444

445

### Serialization Configuration

446

447

```java { .api }

448

import com.hazelcast.config.SerializationConfig;

449

import com.hazelcast.config.SerializerConfig;

450

import com.hazelcast.config.GlobalSerializerConfig;

451

import com.hazelcast.nio.serialization.ByteOrder;

452

453

public class SerializationConfig {

454

// Byte order

455

public SerializationConfig setByteOrder(ByteOrder byteOrder);

456

public ByteOrder getByteOrder();

457

458

// Check class definition errors

459

public SerializationConfig setCheckClassDefErrors(boolean checkClassDefErrors);

460

public boolean isCheckClassDefErrors();

461

462

// Portable version

463

public SerializationConfig setPortableVersion(int portableVersion);

464

public int getPortableVersion();

465

466

// Custom serializers

467

public SerializationConfig addSerializerConfig(SerializerConfig serializerConfig);

468

public Collection<SerializerConfig> getSerializerConfigs();

469

470

// Global serializer

471

public GlobalSerializerConfig getGlobalSerializerConfig();

472

public SerializationConfig setGlobalSerializerConfig(GlobalSerializerConfig globalSerializerConfig);

473

474

// Data serializable factories

475

public SerializationConfig addDataSerializableFactoryClass(int factoryId, String className);

476

public SerializationConfig addDataSerializableFactory(int factoryId, DataSerializableFactory factory);

477

478

// Portable factories

479

public SerializationConfig addPortableFactoryClass(int factoryId, String className);

480

public SerializationConfig addPortableFactory(int factoryId, PortableFactory portableFactory);

481

482

// Java serialization filter

483

public JavaSerializationFilterConfig getJavaSerializationFilterConfig();

484

public SerializationConfig setJavaSerializationFilterConfig(JavaSerializationFilterConfig javaSerializationFilterConfig);

485

}

486

```

487

488

### Serialization Configuration Example

489

490

```java { .api }

491

Config config = new Config();

492

SerializationConfig serializationConfig = config.getSerializationConfig();

493

494

// Custom serializer for User class

495

SerializerConfig userSerializerConfig = new SerializerConfig();

496

userSerializerConfig.setTypeClass(User.class)

497

.setImplementation(new UserSerializer());

498

499

serializationConfig.addSerializerConfig(userSerializerConfig);

500

501

// Portable factory for cross-platform compatibility

502

serializationConfig.addPortableFactory(1, new MyPortableFactory());

503

504

// Java serialization filter for security

505

JavaSerializationFilterConfig filterConfig = new JavaSerializationFilterConfig();

506

filterConfig.setDefaultsDisabled(false);

507

serializationConfig.setJavaSerializationFilterConfig(filterConfig);

508

509

config.setSerializationConfig(serializationConfig);

510

```

511

512

### Security Configuration

513

514

```java { .api }

515

import com.hazelcast.config.SecurityConfig;

516

import com.hazelcast.config.CredentialsFactoryConfig;

517

import com.hazelcast.config.LoginModuleConfig;

518

import com.hazelcast.config.PermissionConfig;

519

520

public class SecurityConfig {

521

// Enable/disable security

522

public SecurityConfig setEnabled(boolean enabled);

523

public boolean isEnabled();

524

525

// Credentials factory

526

public CredentialsFactoryConfig getCredentialsFactoryConfig();

527

public SecurityConfig setCredentialsFactoryConfig(CredentialsFactoryConfig credentialsFactoryConfig);

528

529

// JAAS login modules

530

public List<LoginModuleConfig> getLoginModuleConfigs();

531

public SecurityConfig addLoginModuleConfig(LoginModuleConfig loginModuleConfig);

532

533

// Permissions

534

public Set<PermissionConfig> getClientPermissionConfigs();

535

public SecurityConfig addClientPermissionConfig(PermissionConfig permissionConfig);

536

537

// Security interceptor

538

public SecurityConfig setSecurityInterceptorConfig(SecurityInterceptorConfig securityInterceptorConfig);

539

540

// Client block/unblock

541

public SecurityConfig setClientBlockUnmappedActions(boolean clientBlockUnmappedActions);

542

public boolean getClientBlockUnmappedActions();

543

}

544

```

545

546

### Security Configuration Example

547

548

```java { .api }

549

Config config = new Config();

550

SecurityConfig securityConfig = config.getSecurityConfig();

551

securityConfig.setEnabled(true);

552

553

// Simple credentials factory

554

CredentialsFactoryConfig credentialsFactory = new CredentialsFactoryConfig();

555

credentialsFactory.setClassName("com.example.MyCredentialsFactory");

556

securityConfig.setCredentialsFactoryConfig(credentialsFactory);

557

558

// LDAP login module

559

LoginModuleConfig loginModuleConfig = new LoginModuleConfig();

560

loginModuleConfig.setClassName("com.sun.security.auth.module.LdapLoginModule")

561

.setUsage(LoginModuleConfig.LoginModuleUsage.REQUIRED);

562

563

loginModuleConfig.getProperties().put("userProvider", "ldap://ldap.example.com/ou=People,dc=example,dc=com");

564

loginModuleConfig.getProperties().put("authzIdentity", "{USERNAME}@example.com");

565

566

securityConfig.addLoginModuleConfig(loginModuleConfig);

567

568

// Permission configuration

569

PermissionConfig mapPermission = new PermissionConfig(PermissionConfig.PermissionType.MAP, "sensitive-data", "admin-role");

570

mapPermission.addAction("read").addAction("create").addAction("destroy");

571

572

securityConfig.addClientPermissionConfig(mapPermission);

573

574

config.setSecurityConfig(securityConfig);

575

```

576

577

## Configuration Loading

578

579

### XML Configuration

580

581

```xml

582

<?xml version="1.0" encoding="UTF-8"?>

583

<hazelcast xmlns="http://www.hazelcast.com/schema/config"

584

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

585

xsi:schemaLocation="http://www.hazelcast.com/schema/config

586

http://www.hazelcast.com/schema/config/hazelcast-config-5.5.xsd">

587

588

<instance-name>production-instance</instance-name>

589

<cluster-name>production-cluster</cluster-name>

590

591

<properties>

592

<property name="hazelcast.logging.type">slf4j</property>

593

<property name="hazelcast.operation.call.timeout.millis">30000</property>

594

</properties>

595

596

<network>

597

<port auto-increment="true" port-count="20">5701</port>

598

<interfaces enabled="true">

599

<interface>192.168.1.*</interface>

600

</interfaces>

601

602

<join>

603

<multicast enabled="false"/>

604

<tcp-ip enabled="true">

605

<member>192.168.1.100</member>

606

<member>192.168.1.101</member>

607

<member>192.168.1.102</member>

608

</tcp-ip>

609

</join>

610

</network>

611

612

<map name="user-sessions">

613

<backup-count>2</backup-count>

614

<time-to-live-seconds>1800</time-to-live-seconds>

615

<max-idle-seconds>600</max-idle-seconds>

616

<statistics-enabled>true</statistics-enabled>

617

618

<eviction eviction-policy="LRU" max-size-policy="PER_NODE" size="10000"/>

619

620

<indexes>

621

<index type="HASH">userId</index>

622

<index type="SORTED">lastAccessTime</index>

623

</indexes>

624

</map>

625

626

<queue name="task-queue">

627

<max-size>50000</max-size>

628

<backup-count>1</backup-count>

629

<statistics-enabled>true</statistics-enabled>

630

</queue>

631

632

</hazelcast>

633

```

634

635

### YAML Configuration

636

637

```yaml

638

hazelcast:

639

instance-name: production-instance

640

cluster-name: production-cluster

641

642

properties:

643

hazelcast.logging.type: slf4j

644

hazelcast.operation.call.timeout.millis: 30000

645

646

network:

647

port:

648

auto-increment: true

649

port: 5701

650

port-count: 20

651

652

interfaces:

653

enabled: true

654

interfaces:

655

- 192.168.1.*

656

657

join:

658

multicast:

659

enabled: false

660

tcp-ip:

661

enabled: true

662

members:

663

- 192.168.1.100

664

- 192.168.1.101

665

- 192.168.1.102

666

667

map:

668

user-sessions:

669

backup-count: 2

670

time-to-live-seconds: 1800

671

max-idle-seconds: 600

672

statistics-enabled: true

673

eviction:

674

eviction-policy: LRU

675

max-size-policy: PER_NODE

676

size: 10000

677

indexes:

678

- type: HASH

679

attributes:

680

- userId

681

- type: SORTED

682

attributes:

683

- lastAccessTime

684

685

queue:

686

task-queue:

687

max-size: 50000

688

backup-count: 1

689

statistics-enabled: true

690

```

691

692

### Loading Configuration Files

693

694

```java { .api }

695

// Load from classpath

696

Config config = Config.load();

697

698

// Load from specific file

699

Config config = Config.loadFromFile(new File("/path/to/hazelcast.xml"));

700

Config config = Config.loadFromFile(new File("/path/to/hazelcast.yaml"));

701

702

// Load from stream

703

try (InputStream inputStream = getClass().getResourceAsStream("/hazelcast-config.xml")) {

704

Config config = Config.loadFromStream(inputStream);

705

}

706

707

// Client configuration loading

708

ClientConfig clientConfig = ClientConfig.load();

709

ClientConfig clientConfig = ClientConfig.loadFromFile(new File("/path/to/hazelcast-client.xml"));

710

```

711

712

## Environment-Based Configuration

713

714

### System Properties and Environment Variables

715

716

```java { .api }

717

// System properties

718

System.setProperty("hazelcast.config", "/path/to/hazelcast.xml");

719

System.setProperty("hazelcast.logging.type", "slf4j");

720

721

// Environment variables

722

// HAZELCAST_CONFIG=/path/to/hazelcast.xml

723

// HAZELCAST_LOGGING_TYPE=slf4j

724

725

// Programmatic property override

726

Config config = new Config();

727

config.setProperty("hazelcast.logging.type", "slf4j");

728

config.setProperty("hazelcast.operation.call.timeout.millis", "60000");

729

730

// Instance name from environment

731

String instanceName = System.getenv("HAZELCAST_INSTANCE_NAME");

732

if (instanceName != null) {

733

config.setInstanceName(instanceName);

734

}

735

```

736

737

### Configuration Replacers

738

739

```java { .api }

740

// Using placeholders in configuration

741

Config config = new Config();

742

config.setClusterName("${cluster.name}");

743

744

// Add configuration replacer

745

config.getConfigurationFile(); // This enables property replacement

746

747

// In XML configuration:

748

/*

749

<cluster-name>${CLUSTER_NAME:default-cluster}</cluster-name>

750

<network>

751

<port>${HAZELCAST_PORT:5701}</port>

752

</network>

753

*/

754

```

755

756

## Dynamic Configuration

757

758

### Runtime Configuration Updates

759

760

```java { .api }

761

// Note: Not all configurations can be changed at runtime

762

// This example shows what CAN be changed dynamically

763

764

HazelcastInstance hz = Hazelcast.newHazelcastInstance();

765

766

// Add new map configuration at runtime

767

MapConfig runtimeMapConfig = new MapConfig("runtime-map");

768

runtimeMapConfig.setBackupCount(1);

769

hz.getConfig().addMapConfig(runtimeMapConfig);

770

771

// Get existing configuration

772

Config currentConfig = hz.getConfig();

773

MapConfig existingMapConfig = currentConfig.getMapConfig("user-sessions");

774

System.out.println("Current backup count: " + existingMapConfig.getBackupCount());

775

776

// Some configurations require restart

777

// Network settings, cluster name, etc. cannot be changed at runtime

778

```

779

780

### Configuration Validation

781

782

```java { .api }

783

public class ConfigValidator {

784

785

public static void validateConfig(Config config) {

786

// Validate cluster name

787

if (config.getClusterName() == null || config.getClusterName().trim().isEmpty()) {

788

throw new IllegalArgumentException("Cluster name cannot be empty");

789

}

790

791

// Validate network configuration

792

NetworkConfig network = config.getNetworkConfig();

793

if (network.getPort() < 1024 || network.getPort() > 65535) {

794

throw new IllegalArgumentException("Invalid port number: " + network.getPort());

795

}

796

797

// Validate map configurations

798

for (MapConfig mapConfig : config.getMapConfigs().values()) {

799

validateMapConfig(mapConfig);

800

}

801

802

System.out.println("Configuration validation passed");

803

}

804

805

private static void validateMapConfig(MapConfig mapConfig) {

806

if (mapConfig.getBackupCount() + mapConfig.getAsyncBackupCount() > 6) {

807

throw new IllegalArgumentException(

808

"Total backup count cannot exceed 6 for map: " + mapConfig.getName());

809

}

810

811

if (mapConfig.getTimeToLiveSeconds() < 0) {

812

throw new IllegalArgumentException(

813

"TTL cannot be negative for map: " + mapConfig.getName());

814

}

815

}

816

}

817

818

// Usage

819

try {

820

Config config = new Config();

821

// ... configure

822

823

ConfigValidator.validateConfig(config);

824

HazelcastInstance hz = Hazelcast.newHazelcastInstance(config);

825

} catch (IllegalArgumentException e) {

826

System.err.println("Configuration error: " + e.getMessage());

827

}

828

```

829

830

## Configuration Best Practices

831

832

### Production Configuration Template

833

834

```java { .api }

835

public class ProductionConfigBuilder {

836

837

public static Config buildProductionConfig(String clusterName, String instanceName) {

838

Config config = new Config();

839

840

// Basic settings

841

config.setClusterName(clusterName);

842

config.setInstanceName(instanceName);

843

844

// Logging

845

config.setProperty("hazelcast.logging.type", "slf4j");

846

config.setProperty("hazelcast.logging.class", "com.hazelcast.logging.Slf4jFactory");

847

848

// Operation timeouts

849

config.setProperty("hazelcast.operation.call.timeout.millis", "60000");

850

config.setProperty("hazelcast.operation.backup.timeout.millis", "5000");

851

852

// Health monitoring

853

config.setProperty("hazelcast.health.monitoring.level", "SILENT");

854

config.setProperty("hazelcast.health.monitoring.delay.seconds", "30");

855

856

// Network configuration

857

NetworkConfig network = config.getNetworkConfig();

858

network.setPort(5701)

859

.setPortAutoIncrement(true)

860

.setPortCount(100);

861

862

// Security hardening

863

network.getRestApiConfig().setEnabled(false);

864

network.getMemcacheProtocolConfig().setEnabled(false);

865

866

// Default map configuration

867

MapConfig defaultMapConfig = config.getMapConfig("default");

868

defaultMapConfig.setBackupCount(1)

869

.setAsyncBackupCount(0)

870

.setReadBackupData(false)

871

.setStatisticsEnabled(true);

872

873

return config;

874

}

875

876

public static ClientConfig buildProductionClientConfig(String clusterName) {

877

ClientConfig clientConfig = new ClientConfig();

878

879

clientConfig.setClusterName(clusterName);

880

881

// Connection settings

882

clientConfig.getConnectionStrategyConfig()

883

.setAsyncStart(false)

884

.setReconnectMode(ClientConnectionStrategyConfig.ReconnectMode.ON)

885

.getConnectionRetryConfig()

886

.setInitialBackoffMillis(1000)

887

.setMaxBackoffMillis(30000)

888

.setMultiplier(2.0)

889

.setClusterConnectTimeoutMillis(20000);

890

891

// Network settings

892

clientConfig.getNetworkConfig()

893

.setSmartRouting(true)

894

.setRedoOperation(true)

895

.setConnectionTimeout(5000);

896

897

// Labels for identification

898

clientConfig.addLabel("production-client");

899

900

return clientConfig;

901

}

902

}

903

904

// Usage

905

Config serverConfig = ProductionConfigBuilder.buildProductionConfig("prod-cluster", "server-1");

906

ClientConfig clientConfig = ProductionConfigBuilder.buildProductionClientConfig("prod-cluster");

907

```

908

909

### Configuration for Different Environments

910

911

```java { .api }

912

public class EnvironmentConfigBuilder {

913

914

public static Config forDevelopment() {

915

Config config = new Config();

916

config.setClusterName("dev-cluster");

917

918

// Multicast for easy local discovery

919

config.getNetworkConfig().getJoin()

920

.getMulticastConfig().setEnabled(true)

921

.getTcpIpConfig().setEnabled(false);

922

923

// Minimal backup for faster development

924

config.getMapConfig("default").setBackupCount(0);

925

926

// Verbose logging for debugging

927

config.setProperty("hazelcast.logging.type", "slf4j");

928

929

return config;

930

}

931

932

public static Config forTesting() {

933

Config config = new Config();

934

config.setClusterName("test-cluster");

935

936

// Disable network for unit tests

937

config.getNetworkConfig().getJoin()

938

.getMulticastConfig().setEnabled(false)

939

.getTcpIpConfig().setEnabled(false);

940

941

// Fast shutdown for tests

942

config.setProperty("hazelcast.shutdownhook.enabled", "false");

943

config.setProperty("hazelcast.graceful.shutdown.max.wait", "5");

944

945

return config;

946

}

947

948

public static Config forProduction(String region) {

949

Config config = new Config();

950

config.setClusterName("prod-cluster-" + region);

951

952

// Cloud discovery configuration

953

config.getNetworkConfig().getJoin()

954

.getMulticastConfig().setEnabled(false)

955

.getAwsConfig().setEnabled(true)

956

.setProperty("region", region)

957

.setProperty("tag-key", "hazelcast-cluster")

958

.setProperty("tag-value", "production");

959

960

// Production-level backup and durability

961

config.getMapConfig("default")

962

.setBackupCount(2)

963

.setAsyncBackupCount(1)

964

.setReadBackupData(true);

965

966

// Security enabled

967

config.getSecurityConfig().setEnabled(true);

968

969

return config;

970

}

971

}

972

```