Skip to content

Commit 2246be3

Browse files
Add sample for session resiliency (#761)
Co-authored-by: Jack Green <JackPGreen@Gmail.com>
1 parent 0fa141b commit 2246be3

19 files changed

Lines changed: 711 additions & 154 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@ osgi/felix-cache/
2121
*.code-workspace
2222
dependency-reduced-pom.xml
2323
/enterprise/tls-rbac-demo/keymaterial/
24+
25+
**/licensekey.env

platform-operator/hazelcast-platform-operator-map-store/mapstore/dependency-reduced-pom.xml

Lines changed: 0 additions & 149 deletions
This file was deleted.

spring/pom.xml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,10 @@
5858
<module>spring-boot-caching-jcache</module>
5959
<module>spring-boot-session-replication-spring-session-hazelcast</module>
6060
<module>spring-session-servlet</module>
61+
<module>resilient-sessions</module>
6162
</modules>
6263

6364
<dependencies>
64-
<dependency>
65-
<groupId>com.hazelcast.samples</groupId>
66-
<artifactId>helper</artifactId>
67-
<version>${project.version}</version>
68-
</dependency>
6965
<dependency>
7066
<groupId>com.hazelcast</groupId>
7167
<artifactId>hazelcast</artifactId>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Resilient web sessions example
2+
3+
This example is associated with blog post (link will be posted post-release).
4+
5+
To start a sample cluster, go to `docker` folder, create `licensekey.env` with `HZ_LICENSEKEY=<your key here>` and then run `docker-compose up`.
6+
7+
Individual nodes can be started or stopped using `docker up/down <instance>`, where `<instance>` is either `london-cluster` or `nyc-cluster`.
8+
9+
After that, you can run `Main` class.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
hazelcast:
2+
cluster-name: london-cluster
3+
network:
4+
port:
5+
port-count: 20
6+
auto-increment: true
7+
port:
8+
5701
9+
join:
10+
multicast:
11+
enabled: false
12+
tcp-ip:
13+
enabled: true
14+
member-list:
15+
- london-cluster-1
16+
wan-replication:
17+
replicate-to-nyc:
18+
batch-publisher:
19+
nycPublisher:
20+
cluster-name: nyc-cluster
21+
target-endpoints: "nyc-cluster-1:5701"
22+
map:
23+
shopSessions:
24+
wan-replication-ref:
25+
replicate-to-nyc:
26+
merge-policy-class-name: PutIfAbsentMergePolicy
27+
backup-count: 1
28+
# because we are modifying IMap's config not via sessionMapConfigCustomizer, we need to add the index manually
29+
indexes:
30+
- type: HASH
31+
attributes:
32+
- "principalName"
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
hazelcast:
2+
cluster-name: nyc-cluster
3+
network:
4+
port:
5+
port-count: 20
6+
auto-increment: true
7+
port:
8+
5701
9+
join:
10+
multicast:
11+
enabled: false
12+
tcp-ip:
13+
enabled: true
14+
member-list:
15+
- nyc-cluster-1
16+
wan-replication:
17+
replicate-to-lon:
18+
batch-publisher:
19+
lonPublisher:
20+
cluster-name: london-cluster
21+
target-endpoints: "london-cluster-1:5701"
22+
map:
23+
shopSessions:
24+
wan-replication-ref:
25+
replicate-to-lon:
26+
merge-policy-class-name: PutIfAbsentMergePolicy
27+
backup-count: 1
28+
# because we are modifying IMap's config not via sessionMapConfigCustomizer, we need to add the index manually
29+
indexes:
30+
- type: HASH
31+
attributes:
32+
- "principalName"
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: resilient-sessions
2+
3+
services:
4+
london-cluster:
5+
image: hazelcast/hazelcast-enterprise:latest
6+
hostname: london-cluster-1
7+
ports:
8+
- "5701:5701"
9+
volumes:
10+
- ./conf-lon:/opt/hazelcast/config
11+
env_file:
12+
- licensekey.env
13+
environment:
14+
- HAZELCAST_CONFIG=/opt/hazelcast/config/config.yml
15+
16+
nyc-cluster:
17+
image: hazelcast/hazelcast-enterprise:latest
18+
hostname: nyc-cluster-1
19+
ports:
20+
- "5702:5701"
21+
volumes:
22+
- ./conf-newyork:/opt/hazelcast/config
23+
env_file:
24+
- licensekey.env
25+
environment:
26+
- HAZELCAST_CONFIG=/opt/hazelcast/config/config.yml
27+
28+
management-center:
29+
image: hazelcast/management-center:latest
30+
ports:
31+
- "8180:8080"
32+
env_file:
33+
- licensekey.env

spring/resilient-sessions/pom.xml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<artifactId>resilient-sessions</artifactId>
8+
<parent>
9+
<groupId>com.hazelcast.samples</groupId>
10+
<artifactId>spring</artifactId>
11+
<version>0.1-SNAPSHOT</version>
12+
</parent>
13+
14+
<properties>
15+
<hazelcast.version>5.6.0</hazelcast.version>
16+
<spring.version>7.0.2</spring.version>
17+
<spring-boot.version>4.0.0</spring-boot.version>
18+
19+
<!-- needed for checkstyle/findbugs -->
20+
<main.basedir>${project.parent.parent.basedir}</main.basedir>
21+
</properties>
22+
23+
<repositories>
24+
<repository>
25+
<id>Hazelcast Private Snapshot Repository</id>
26+
<url>https://repository.hazelcast.com/snapshot/</url>
27+
<releases>
28+
<enabled>false</enabled>
29+
</releases>
30+
</repository>
31+
<repository>
32+
<id>Hazelcast Private Release Repository</id>
33+
<url>https://repository.hazelcast.com/release/</url>
34+
<snapshots>
35+
<enabled>false</enabled>
36+
</snapshots>
37+
</repository>
38+
</repositories>
39+
40+
<dependencies>
41+
<!-- TODO update post-release -->
42+
<dependency>
43+
<groupId>com.hazelcast.spring</groupId>
44+
<artifactId>hazelcast-spring-session</artifactId>
45+
<version>4.0.0-RC2</version>
46+
<exclusions>
47+
<exclusion>
48+
<groupId>com.hazelcast</groupId>
49+
<artifactId>hazelcast</artifactId>
50+
</exclusion>
51+
</exclusions>
52+
</dependency>
53+
<dependency>
54+
<groupId>com.hazelcast</groupId>
55+
<artifactId>hazelcast-enterprise</artifactId>
56+
<version>${hazelcast.version}</version>
57+
</dependency>
58+
<dependency>
59+
<groupId>com.hazelcast</groupId>
60+
<artifactId>hazelcast-spring</artifactId>
61+
<version>${hazelcast.version}</version>
62+
</dependency>
63+
64+
<dependency>
65+
<groupId>org.springframework.boot</groupId>
66+
<artifactId>spring-boot-starter-webmvc</artifactId>
67+
<version>${spring-boot.version}</version>
68+
</dependency>
69+
<dependency>
70+
<groupId>org.springframework.boot</groupId>
71+
<artifactId>spring-boot-hazelcast</artifactId>
72+
<version>${spring-boot.version}</version>
73+
</dependency>
74+
75+
<dependency>
76+
<groupId>org.jspecify</groupId>
77+
<artifactId>jspecify</artifactId>
78+
<version>1.0.0</version>
79+
</dependency>
80+
81+
<dependency>
82+
<groupId>org.springframework.security</groupId>
83+
<artifactId>spring-security-web</artifactId>
84+
<version>${spring.version}</version>
85+
</dependency>
86+
<dependency>
87+
<groupId>org.springframework.security</groupId>
88+
<artifactId>spring-security-core</artifactId>
89+
<version>${spring.version}</version>
90+
</dependency>
91+
<dependency>
92+
<groupId>org.springframework.security</groupId>
93+
<artifactId>spring-security-config</artifactId>
94+
<version>${spring.version}</version>
95+
</dependency>
96+
</dependencies>
97+
98+
</project>

0 commit comments

Comments
 (0)