You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sd...@apache.org on 2022/08/30 08:30:17 UTC
[ignite-extensions] branch master updated: IGNITE-17381 Add docs for Ignite Sessions - Fixes #166
This is an automated email from the ASF dual-hosted git repository.
sdanilov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite-extensions.git
The following commit(s) were added to refs/heads/master by this push:
new 9b8e2b1 IGNITE-17381 Add docs for Ignite Sessions - Fixes #166
9b8e2b1 is described below
commit 9b8e2b1dac747b1ec301f69919e45ae747706881
Author: IgGusev <de...@mail.ru>
AuthorDate: Fri Jul 15 15:59:53 2022 +0400
IGNITE-17381 Add docs for Ignite Sessions - Fixes #166
---
docs/_data/toc.yaml | 2 +
docs/_docs/spring/spring-sessions.adoc | 110 +++++++++++++++++++++
.../spring/sessions/EnableIgniteHttpSession.java | 4 +-
3 files changed, 113 insertions(+), 3 deletions(-)
diff --git a/docs/_data/toc.yaml b/docs/_data/toc.yaml
index 6e86993..2ddc5fa 100644
--- a/docs/_data/toc.yaml
+++ b/docs/_data/toc.yaml
@@ -32,6 +32,8 @@
url: spring/spring-data
- title: Apache Ignite and Spring Cache
url: spring/spring-caching
+- title: Apache Ignite and Spring Session
+ url: spring/spring-sessions
- title: Apache Ignite and Spring Transactions
url: spring/spring-tx
- title: Apache Kafka Streamer
diff --git a/docs/_docs/spring/spring-sessions.adoc b/docs/_docs/spring/spring-sessions.adoc
new file mode 100644
index 0000000..875cd23
--- /dev/null
+++ b/docs/_docs/spring/spring-sessions.adoc
@@ -0,0 +1,110 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+= Apache Ignite With Spring Session
+
+== Overview
+
+
+Apache Ignite Spring Session integration provides SessionRepository and IndexedSessionRepository implementation and configuration support. Spring Session simplifies support for clustered sessions without being tied to an application container specific solution.
+
+
+== Maven Configuration
+
+Add the `ignite-spring-session-ext` extension to your Maven to use your Ignite cluster for Spring Session storage and replication. Here is how you can add this extension to your project:
+
+[tabs]
+--
+tab:pom.xml[]
+[source,xml]
+----
+<dependencies>
+ <dependency>
+ <groupId>org.springframework.session</groupId>
+ <artifactId>spring-session-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.ignite</groupId>
+ <artifactId>ignite-spring-session-ext</artifactId>
+ <version>1.0.0</version>
+ </dependency>
+</dependencies>
+----
+--
+
+=== Set Ignite Up Programmatically
+
+To expose Spring Sessions to Ignite:
+
+- Add the `@EnableIgniteHttpSession` annotation to the class that configures Ignite session.
+- Add the `@SpringSessionIgnite` annotation to your Ignite instance.
+
+Here is how you can add these annotations:
+
+[source,java]
+----
+@Configuration
+@EnableIgniteHttpSession
+public class SessionConfiguration {
+ @Bean
+ @SpringSessionIgnite
+ public Ignite ignite() {
+ IgniteConfiguration cfg = new IgniteConfiguration();
+
+ TcpDiscoverySpi tcpDiscoverySpi = new TcpDiscoverySpi();
+
+ tcpDiscoverySpi.setLocalAddress("127.0.0.1")
+ .setLocalPort(47500)
+ .setLocalPortRange(10);
+
+ cfg.setDiscoverySpi();
+
+ return Ignition.start(cfg);
+ }
+}
+----
+
+After you add these annotations, Spring Session will use Ignite as a data storage for sessions. For example, here is how you can create a simple controller:
+
+[source,java]
+----
+@Controller
+public class SampleController {
+ @GetMapping("/")
+ public String SessionId(HttpSession session) {
+ return session.getId();
+ }
+}
+----
+
+
+== Configuration
+
+
+`@EnableIgniteHttpSession` annotation provides arguments to configure the session storage:
+
+- `maxInactiveIntervalInSeconds` – session timeout in seconds. By default, it is set to 1800 seconds (30 minutes).
+- `sessionMapName` – the name of the distributed map that will be used in Ignite to store the session data.
+By default, it is set to `"spring:session:sessions"`.
+- `flushMode` – flush mode for the Ignite sessions.
+The default is `FlushMode#ON_SAVE` which only updates the backing distributed storage when `SessionRepository#save(Session)` is invoked.
+In a web environment this happens just before the HTTP response is committed.
+- `saveMode` – save mode for the session. The default is `SaveMode#ON_SET_ATTRIBUTE`, which
+only saves changes made to session.
+
+
+== Example
+
+
+You can find an example in the https://github.com/antkr/ignite-spring-session-demo[example repository, windows="_blank"]. In it, an Ignite node is started with a Spring Session controller.
diff --git a/modules/spring-session-ext/src/main/java/org/apache/ignite/spring/sessions/EnableIgniteHttpSession.java b/modules/spring-session-ext/src/main/java/org/apache/ignite/spring/sessions/EnableIgniteHttpSession.java
index 787496f..229ac87 100644
--- a/modules/spring-session-ext/src/main/java/org/apache/ignite/spring/sessions/EnableIgniteHttpSession.java
+++ b/modules/spring-session-ext/src/main/java/org/apache/ignite/spring/sessions/EnableIgniteHttpSession.java
@@ -80,10 +80,9 @@ public @interface EnableIgniteHttpSession {
* updates the backing Ignite when {@link SessionRepository#save(Session)} is invoked.
* In a web environment this happens just before the HTTP response is committed.
* <p>
- * Setting the value to {@code IMMEDIATE} will ensure that the any updates to the
+ * Setting the value to {@code IMMEDIATE} will ensure that any updates to the
* Session are immediately written to the Ignite instance.
* @return the {@link FlushMode} to use
- * @since 2.2.0
*/
FlushMode flushMode() default FlushMode.ON_SAVE;
@@ -91,7 +90,6 @@ public @interface EnableIgniteHttpSession {
* Save mode for the session. The default is {@link SaveMode#ON_SET_ATTRIBUTE}, which
* only saves changes made to session.
* @return the save mode
- * @since 2.2.0
*/
SaveMode saveMode() default SaveMode.ON_SET_ATTRIBUTE;