Skip to content

AndreasKl/reactive-spring-session-vertx

Repository files navigation

Build Status Maven Central javadoc

reactive-spring-session-vertx

Due to the lack of a distributed reactive Spring Session implementations for relational databases, this projects aims to fill the gap with a fully reactive PostgreSQL Spring Session store.

The implementation is based on vertx-sql-client.

Supports JDK 8 and up. Does not depend on Spring Boot but can be easily used with Spring Boot.

Setup instructions

A demo project is located under /reactive-spring-session-sample-app written in Kotlin. ReactivePostgresSessionConfiguration registers a ReactivePostgresSessionRepository and a scheduled task that removes expired sessions from the database. Expired sessions are never returned to the user, however could remain in the database until the scheduler does the cleanup.

@Configuration
@Import(ReactivePostgresSessionConfiguration::class)
class PostgresSessionConfiguration {

  @Bean
  fun pgConnectOptions(@Value("\${postgres.port}") postgresPort: Int): PgConnectOptions =
    PgConnectOptions()
      .setHost("localhost")
      .setPort(postgresPort)
      .setDatabase("session")
      .setUser("postgres")
      .setPassword("postgres")
      .setIdleTimeout(300)
      .setConnectTimeout(500)

  @Bean
  fun poolOptions(): PoolOptions =
    PoolOptions()
      .setMaxSize(5)
      .setMaxWaitQueueSize(10)

  @Bean
  fun clock(): Clock =
    Clock.systemUTC()

  @Bean(WebHttpHandlerBuilder.WEB_SESSION_MANAGER_BEAN_NAME)
  fun webSessionManager(repository: ReactiveSessionRepository<out Session>): WebSessionManager {
    val sessionStore = SpringSessionWebSessionStore(repository)

    val manager = DefaultWebSessionManager()
    manager.sessionStore = sessionStore
    return manager
  }

}

Is this production ready?

reactive-spring-session-vertx is used in production @REWE digital for their Spring Gateway based reactive API gateway.

Build

Just test and build, will start Postgres as embedded databases:

mvn clean verify

Deploy the current SNAPSHOT to oss.sonatype.org:

mvn -P release -pl reactive-spring-session-postgres -am clean deploy

Deploy a RELEASE to oss.sonatype.org:

mvn release:prepare

mvn -P release clean deploy

mvn -P release nexus-staging:rc-list

mvn -P release -DstagingRepositoryId=netandreaskluth-<some-id>  nexus-staging:release

Contributing

Source code formatting is checked with fmt-maven-plugin. Configuration files for the formatter of your preferred IDE can be found here a plugin for IntelliJ IDEA can be found here.

License

The MIT License (https://opensource.org/licenses/MIT)

About

Reactive spring session implementation for postgres using eclipse-vertx/vertx-sql-client. Made with ☕

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •