Skip to content

Add sample for session resiliency#761

Merged
TomaszGaweda merged 25 commits intohazelcast:masterfrom
TomaszGaweda:add-session-resilience-and-analysis-example
Feb 13, 2026
Merged

Add sample for session resiliency#761
TomaszGaweda merged 25 commits intohazelcast:masterfrom
TomaszGaweda:add-session-resilience-and-analysis-example

Conversation

@TomaszGaweda
Copy link
Contributor

Adds example of web session resiliency using Hazelcast Spring Session.

Checklist:

  • Request reviewers if possible
  • README.md or README.adoc is created with a description what example does and how to run it
  • Add tests that reproduce the associated tutorial or similar scenario

@TomaszGaweda
Copy link
Contributor Author

So far it will fail - until full release

@@ -0,0 +1,7 @@
# Resilient web sessions example

This example is associated with blog post.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What blog post? Can you link to it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not released yet :(

Comment on lines +11 to +15
<!-- <parent>-->
<!-- <groupId>com.hazelcast.samples</groupId>-->
<!-- <artifactId>spring</artifactId>-->
<!-- <version>0.1-SNAPSHOT</version>-->
<!-- </parent>-->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use the parent?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It gets very confused with dependencies. Apparently now it started working, idk what was wrong...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a must that it uses the parent. The repo is barely maintainable as it is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uses it now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need a new (nested) .gitignore?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to hide file with environment variable for HZ_LICENSEKEY

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we add that the parent gitignore?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok 8ab6f9a

TomaszGaweda and others added 6 commits February 9, 2026 21:05
…rties

Co-authored-by: Jack Green <JackPGreen@Gmail.com>
Co-authored-by: Jack Green <JackPGreen@Gmail.com>
…AnalysisController.java

Co-authored-by: Jack Green <JackPGreen@Gmail.com>
@JackPGreen
Copy link
Contributor

@TomaszGaweda FYI still previous outstanding coments.

@TomaszGaweda
Copy link
Contributor Author

I think everything is addressed now, can you please recheck? @JackPGreen

Comment on lines +47 to +48
record SessionReminderDto(String sessionId, String userId, String timeStatus, List<BasketItem> items, BigDecimal totalPrice) {
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be in the model package? Seems unconventional to declare a DTO as a nested class.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing special in case of Jet classes. I thought about putting it in the method itself :P

model package was meant to be the main model for the shop. I've moved the controller to new package and extracted DTO just to make things clear.

var basket = s.getAttribute("basket").deserialize(hz, Basket.class);

Instant lastAccessedTime = s.getLastAccessedTime();
String timeStatus = Instant.now().isAfter(lastAccessedTime.plusSeconds(30))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be more readable as:
Duration.between(lastAccessedTime, Instant.now()).getSeconds() > 30

Probably less JSR-310-style though, but for a blog post...

Copy link
Contributor Author

@TomaszGaweda TomaszGaweda Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made it a solution in between - using Duration.between (good idea) and compareTo a constant

Comment on lines +69 to +71
BigDecimal totalValue = basket.items().stream()
.map(item -> item.orderPrice().multiply(new BigDecimal(item.quantity())))
.reduce(BigDecimal.ZERO, BigDecimal::add);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not immediately obvious why we need BigDecimal here. I can guess... but last time I did that I was very wrong. Maybe add a comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added explanation as JavaDoc in DTO

TomaszGaweda and others added 6 commits February 10, 2026 21:10
…ShopConfiguration.java

Co-authored-by: Jack Green <JackPGreen@Gmail.com>
Co-authored-by: Jack Green <JackPGreen@Gmail.com>
…sis-example' into add-session-resilience-and-analysis-example

/**
* @param product product information
* @param orderPrice order price of the item; {@link BigDecimal} to make floating-point errors in calculations less likely.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is BigDecimal overkill for a code-sample?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say it's something typical. After working for 5.5 years on an accounting app I iust had a muscle memory to use it :p

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to work on your rounding errors.


<properties>
<maven.compiler.release>17</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sure we can inherit this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't checked - but are any of these dependencies overlapping? E.G. does spring boot bring in spring-core?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spring Security does not, Spring Boot does bring Spring Web, but I wanted to pin to newer version.

Co-authored-by: Jack Green <JackPGreen@Gmail.com>
@TomaszGaweda TomaszGaweda merged commit 2246be3 into hazelcast:master Feb 13, 2026
3 checks passed
@TomaszGaweda TomaszGaweda deleted the add-session-resilience-and-analysis-example branch February 13, 2026 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants