You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
redisson/redisson-tomcat/README.md

79 lines
4.0 KiB
Markdown

# Redis based Tomcat Session Manager
8 years ago
Stores session of [Apache Tomcat](http://tomcat.apache.org) in Redis and allows to distribute requests across a cluster of Tomcat servers. Implements non-sticky session management backed by Redis.
8 years ago
4 years ago
Supports Apache Tomcat 7.x, 8.x, 9.x, 10.x
8 years ago
## Usage
8 years ago
4 years ago
### 1. Add session manager
6 years ago
4 years ago
Add `RedissonSessionManager` in global context - `tomcat/conf/context.xml` or per application context - `tomcat/conf/server.xml`
8 years ago
```xml
<Manager className="org.redisson.tomcat.RedissonSessionManager"
6 years ago
configPath="${catalina.base}/redisson.conf"
5 years ago
readMode="REDIS" updateMode="DEFAULT" broadcastSessionEvents="false"
keyPrefix=""/>
8 years ago
```
5 years ago
`keyPrefix` - string prefix applied to all Redis keys. Allows to connection different Tomcat envirounments to the same Redis instance.
6 years ago
`readMode` - read Session attributes mode. Two modes are available:
6 years ago
* `MEMORY` - stores attributes into local Tomcat Session and Redis. Further Session updates propagated to local Tomcat Session using Redis-based events.
* `REDIS` - stores attributes into Redis only. Default mode.
7 years ago
<br/>
6 years ago
`broadcastSessionEvents` - if `true` then `sessionCreated` and `sessionDestroyed` events are broadcasted across all Tomcat instances and cause all registered HttpSessionListeners to be triggered. Default is `false`.
4 years ago
4 years ago
`broadcastSessionUpdates` - if `true` and `readMode=MEMORY` then session updates are broadcasted across all Tomcat instances. Default is `true`.
6 years ago
`updateMode` - Session attributes update mode. Two modes are available:
5 years ago
* `DEFAULT` - session attributes are stored into Redis only through `Session.setAttribute` method. Default mode.
* `AFTER_REQUEST` - all session attributes are stored into Redis after each request. It useful in case when some objects stored in session change own state without `Session.setAttribute` method execution.
7 years ago
<br/>
5 years ago
`configPath` - path to Redisson YAML config. See [configuration wiki page](https://github.com/redisson/redisson/wiki/2.-Configuration) for more details.
8 years ago
6 years ago
#### Shared Redisson instance
5 years ago
Amount of Redisson instances created by Tomcat for multiple contexts could be reduced through JNDI registry:
6 years ago
1. Add shared redisson instance produced by `JndiRedissonFactory` into `tomcat/conf/server.xml` in `GlobalNamingResources` tag area:
```xml
<GlobalNamingResources>
<Resource name="bean/redisson"
6 years ago
auth="Container"
6 years ago
factory="org.redisson.JndiRedissonFactory"
6 years ago
configPath="${catalina.base}/conf/redisson.yaml"
closeMethod="shutdown"/>
6 years ago
</GlobalNamingResources>
```
2. Add `JndiRedissonSessionManager` with resource link to redisson instance into `tomcat/conf/context.xml`
```xml
<ResourceLink name="bean/redisson"
global="bean/redisson"
type="org.redisson.api.RedissonClient" />
<Manager className="org.redisson.tomcat.JndiRedissonSessionManager"
readMode="REDIS"
jndiName="bean/redisson" />
```
6 years ago
### 2. Copy two jars into `TOMCAT_BASE/lib` directory:
8 years ago
4 years ago
[redisson-all-3.16.1.jar](https://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=org.redisson&a=redisson-all&v=3.16.1&e=jar)
8 years ago
4 years ago
Tomcat 7.x - [redisson-tomcat-7-3.16.1.jar](https://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=org.redisson&a=redisson-tomcat-7&v=3.16.1&e=jar)
4 years ago
4 years ago
Tomcat 8.x - [redisson-tomcat-8-3.16.1.jar](https://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=org.redisson&a=redisson-tomcat-8&v=3.16.1&e=jar)
4 years ago
4 years ago
Tomcat 9.x - [redisson-tomcat-9-3.16.1.jar](https://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=org.redisson&a=redisson-tomcat-9&v=3.16.1&e=jar)
4 years ago
4 years ago
Tomcat 10.x - [redisson-tomcat-10-3.16.1.jar](https://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=org.redisson&a=redisson-tomcat-10&v=3.16.1&e=jar)
4 years ago
Consider __[Redisson PRO](https://redisson.pro)__ version for **ultra-fast performance** and **support by SLA**.