Skip to content

Latest commit

 

History

History
105 lines (72 loc) · 3.58 KB

README.md

File metadata and controls

105 lines (72 loc) · 3.58 KB

spring-session-aerospike

Store HTTP session data in Aerospike for Spring MVC web application with optional compression and customizable serialization.

Overview

An HTTP session manager implementation that stores sessions in Aerospike for easy distribution of requests across a cluster of web servers.

Sessions are stored into Aerospike immediately upon creation for use by other servers. Sessions are loaded as requested directly from Aerospike. In order to prevent collisions (and lost writes) as much as possible, session data is only updated in Aerospike if the session has been modified.

Data stored in the session must be Serializable.

Installation

To use the latest release in your application, use this dependency entry in your pom.xml

<dependency>
   <groupId>us.swcraft.springframework</groupId>
   <artifactId>spring-session-aerospike</artifactId>
   <version>0.0.16</version>
</dependency>

Add Aerospike java client dependecy:

<dependency>
   <groupId>com.aerospike</groupId>
   <artifactId>aerospike-client</artifactId>
   <version>5.1.11</version>
</dependency>

Architecture

  • provides the session creation, saving, and loading functionality.
  • ensures that sessions are saved after a request is finished processing.

Usage

Enabe Aerospike HTTP session storage

Add @EnableAerospikeHttpSession annotation to the configuration java class file and define aerospikeClient client bean.

Annotation parameters:

maxInactiveIntervalInSeconds - set the maximum inactive interval in seconds between requests before newly created sessions will be invalidated. A negative time indicates that the session will never timeout. The default is 1800 (30 minutes).

namespace - Aerospike namespace name for session data. Default is cache.

setname - Aerospike set name for session data. Default is httpsession.

serializationType - Session data serialization type. Supported types:

  • FST - fast serialization (default).
  • KRYO - binary object graph serialization framework for Java.

compression - Store compression type. Supported types:

  • NONE - No data compession (default).
  • SNAPPY - Snappy compression/decompression.

All parameters defined sample:

@EnableAerospikeHttpSession(maxInactiveIntervalInSeconds = 600,
   namespace = "cache", setname = "myhttpsession",
   serializationType = StoreSerializationType.KRYO, compression = StoreCompression.SNAPPY)

Aerospike client configuration

@Configuration
@EnableAerospikeHttpSession
public class SessionStoreConfiguration {
    
    @Autowire
    private Environment env;

    @Bean(destroyMethod = "close")
    public IAerospikeClient aerospikeClient() throws Exception {
        final ClientPolicy defaultClientPolicy = new ClientPolicy();
        final IAerospikeClient client = new AerospikeClient(defaultClientPolicy,
                new Host(
                        env.getProperty("aerospike.session.store.host", "localhost"),
                        Integer.valueOf(env.getProperty("aerospike.session.store.port", "3000")))
                        );
        return client;
    }

}

In this simple example a single aerospike node is defined as application properties aerospike.session.store.host and aerospike.session.store.port

application.properties example:

aerospike.session.store.host = localhost
aerospike.session.store.port = 3000

Acknowledgements

The architecture of this project was inspired by and based on Redis support in "spring-session".