Skip to content

Commit 4064936

Browse files
author
Juraj Veverka
committed
hazelcast cluster demo created
1 parent a4e885d commit 4064936

File tree

24 files changed

+1186
-0
lines changed

24 files changed

+1186
-0
lines changed

hazelcast-cluster/.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.gradle
2+
.settings
3+
bin
4+
out
5+
build
6+
target
7+
.classpath
8+
.project
9+
.idea
10+
*.iml
11+

hazelcast-cluster/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Hazelcast cluster demo
2+
Simple clustering demo using hazelcast and jetty to create application cluster.
3+
When instances of server-node are started on same network, they form hazelcast cluster automatically.
4+
Architecture below shows 3-node cluster example. This cluster application is dynamic, nodes may be added or removed.
5+
6+
### use of proto3 messages
7+
Data objects stored in hazelcast are proto3 messages defined in [messages.proto](common/src/main/proto/messages.proto).
8+
The reason why [proto3](https://developers.google.com/protocol-buffers/docs/proto3) message format is used,
9+
is that this example avoids standard java serialization and reuses serialization and deserialization provided by proto3 messages.
10+
11+
## Architecture
12+
![](docs/architecture-01.svg)
13+
14+
15+
## Build and run
16+
```gradle clean build installDist distZip```
17+
18+
Start server-node instance.
19+
```./server-node/build/install/server-node/bin/server-node```
20+
Web server port id set to avoid conflict on same ip-address.
21+
First server-node started will use port 8080, second server-node in cluster will use web server port 8081,
22+
third will use 8082 an so on.
23+
24+
## Run integration tests
25+
TODO

hazelcast-cluster/build.gradle

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
subprojects {
2+
3+
apply plugin: "java"
4+
5+
/*
6+
target compatibility should be 11, but due to several issues with gradle / asm
7+
is for now target compatibility set to 10
8+
https://github.com/gradle/gradle/issues/5120
9+
https://github.com/gradle/gradle/issues/5731
10+
*/
11+
targetCompatibility = '10'
12+
sourceCompatibility = '10'
13+
14+
repositories {
15+
mavenCentral()
16+
}
17+
18+
dependencies {
19+
compile 'org.slf4j:slf4j-api:1.8.0-beta2'
20+
compile 'org.slf4j:slf4j-simple:1.8.0-beta2'
21+
}
22+
}
23+
24+
project(':common') {
25+
}
26+
27+
project(':server-node') {
28+
dependencies {
29+
compile project(':common')
30+
}
31+
}
32+
33+
project(':it-tests') {
34+
dependencies {
35+
compile project(':common')
36+
compile project(':server-node')
37+
}
38+
}
39+
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
apply plugin: 'java'
2+
apply plugin: 'maven'
3+
apply plugin: 'idea'
4+
apply plugin: 'application'
5+
apply plugin: 'com.google.protobuf'
6+
7+
buildscript {
8+
repositories {
9+
mavenCentral()
10+
}
11+
dependencies {
12+
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.6'
13+
}
14+
}
15+
16+
repositories {
17+
mavenLocal()
18+
mavenCentral()
19+
}
20+
21+
sourceCompatibility = 11
22+
targetCompatibility = 11
23+
24+
def grpcVersion = '1.13.2'
25+
mainClassName = 'itx.examples.grpc.service.Main'
26+
27+
dependencies {
28+
compile 'org.slf4j:slf4j-api:1.8.0-beta2'
29+
compile 'org.slf4j:slf4j-simple:1.8.0-beta2'
30+
compile 'com.beust:jcommander:1.72'
31+
32+
compile "com.google.api.grpc:proto-google-common-protos:1.12.0"
33+
compile "io.grpc:grpc-netty:${grpcVersion}"
34+
compile "io.grpc:grpc-protobuf:${grpcVersion}"
35+
compile "io.grpc:grpc-stub:${grpcVersion}"
36+
37+
compile 'javax.annotation:javax.annotation-api:1.3.2'
38+
39+
testCompile "io.grpc:grpc-testing:${grpcVersion}"
40+
testCompile 'org.testng:testng:6.14.3'
41+
}
42+
43+
protobuf {
44+
protoc {
45+
artifact = 'com.google.protobuf:protoc:3.3.0'
46+
}
47+
plugins {
48+
grpc {
49+
artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}"
50+
}
51+
}
52+
generateProtoTasks {
53+
all()*.plugins {
54+
grpc {
55+
option 'enable_deprecated=false'
56+
}
57+
}
58+
}
59+
}
60+
61+
idea {
62+
module {
63+
// Not using generatedSourceDirs because of
64+
// https://discuss.gradle.org/t/support-for-intellij-2016/15294/8
65+
sourceDirs += file("${projectDir}/build/generated/source/proto/main/java");
66+
sourceDirs += file("${projectDir}/build/generated/source/proto/main/grpc");
67+
}
68+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
syntax = "proto3";
3+
4+
option java_multiple_files = true;
5+
option java_package = "itx.hazelcast.cluster.dto";
6+
7+
message InstanceInfo {
8+
string id = 1;
9+
Address address = 2;
10+
int32 webServerPort = 3;
11+
}
12+
13+
message Address {
14+
string hostName = 1;
15+
int32 port = 2;
16+
}

0 commit comments

Comments
 (0)