Add sample for session resiliency#761
Conversation
|
So far it will fail - until full release |
spring/resilient-sessions/README.md
Outdated
| @@ -0,0 +1,7 @@ | |||
| # Resilient web sessions example | |||
|
|
|||
| This example is associated with blog post. | |||
There was a problem hiding this comment.
What blog post? Can you link to it?
There was a problem hiding this comment.
Not released yet :(
spring/resilient-sessions/pom.xml
Outdated
| <!-- <parent>--> | ||
| <!-- <groupId>com.hazelcast.samples</groupId>--> | ||
| <!-- <artifactId>spring</artifactId>--> | ||
| <!-- <version>0.1-SNAPSHOT</version>--> | ||
| <!-- </parent>--> |
There was a problem hiding this comment.
It gets very confused with dependencies. Apparently now it started working, idk what was wrong...
There was a problem hiding this comment.
I think it's a must that it uses the parent. The repo is barely maintainable as it is.
spring/resilient-sessions/.gitignore
Outdated
There was a problem hiding this comment.
Why do we need a new (nested) .gitignore?
There was a problem hiding this comment.
Just to hide file with environment variable for HZ_LICENSEKEY
There was a problem hiding this comment.
Can't we add that the parent gitignore?
spring/resilient-sessions/src/main/java/com/hazelcast/samples/model/Basket.java
Outdated
Show resolved
Hide resolved
spring/resilient-sessions/src/main/java/com/hazelcast/samples/SecurityConfig.java
Show resolved
Hide resolved
spring/resilient-sessions/src/main/java/com/hazelcast/samples/ShopConfiguration.java
Outdated
Show resolved
Hide resolved
spring/resilient-sessions/src/main/java/com/hazelcast/samples/ShopConfiguration.java
Show resolved
Hide resolved
spring/resilient-sessions/src/main/java/com/hazelcast/samples/ShopConfiguration.java
Outdated
Show resolved
Hide resolved
spring/resilient-sessions/src/main/resources/application.properties
Outdated
Show resolved
Hide resolved
…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>
|
@TomaszGaweda FYI still previous outstanding coments. |
|
I think everything is addressed now, can you please recheck? @JackPGreen |
| record SessionReminderDto(String sessionId, String userId, String timeStatus, List<BasketItem> items, BigDecimal totalPrice) { | ||
| } |
There was a problem hiding this comment.
Should this be in the model package? Seems unconventional to declare a DTO as a nested class.
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
Might be more readable as:
Duration.between(lastAccessedTime, Instant.now()).getSeconds() > 30
Probably less JSR-310-style though, but for a blog post...
There was a problem hiding this comment.
Made it a solution in between - using Duration.between (good idea) and compareTo a constant
| BigDecimal totalValue = basket.items().stream() | ||
| .map(item -> item.orderPrice().multiply(new BigDecimal(item.quantity()))) | ||
| .reduce(BigDecimal.ZERO, BigDecimal::add); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Added explanation as JavaDoc in DTO
spring/resilient-sessions/src/main/java/com/hazelcast/samples/ShopConfiguration.java
Show resolved
Hide resolved
…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. |
There was a problem hiding this comment.
Is BigDecimal overkill for a code-sample?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
I think you need to work on your rounding errors.
spring/resilient-sessions/pom.xml
Outdated
|
|
||
| <properties> | ||
| <maven.compiler.release>17</maven.compiler.release> | ||
| <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
There was a problem hiding this comment.
I'm sure we can inherit this?
There was a problem hiding this comment.
I haven't checked - but are any of these dependencies overlapping? E.G. does spring boot bring in spring-core?
There was a problem hiding this comment.
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>
Adds example of web session resiliency using Hazelcast Spring Session.
Checklist: