jetty-session-redis
Jetty session clustering with REDIS
REDIS website (tested on version 2.2.1)
JEDIS website (tested on version 1.5.2)
Jetty website (tested on version 8.0.0.M2)
Build instruction:
git clone git://github.com/Ovea/jetty-session-redis.git
cd jetty-session-redis
mvn package
Download
All downloads are here. They will also be available in Maven central repository and also in Sonatype OSS repositories soon:
Snapshots - in Sonatype OSS Repository
Releases - in Sonatype OSS Repository
Releases - in Maven Central Repository
See the section below to know which package you need (the jar file or the -all bundle).
Installation
You need to put in Jetty's lib/ext folder:
jedis // https://github.com/downloads/xetorthio/jedis/jedis-2.1.0.jar
commons-pool // http://mirrors.cnnic.cn/apache//commons/pool/binaries/commons-pool-1.6-bin.tar.gz
and one of the following JAR:
jetty-session-redis-X.Y.jar (if you are going to put all serializer dependencies also as independant jar files)
jetty-session-redis-X.Y-all.jar (contains already packaged-relocated serializers)
I strongly recommand you use the jetty-session-redis-X.Y-all.jar because some serializers (like JBoss Serializer) have been improved for performance.
Configuration
In Jetty server configuration file (i.e. jetty.xml):
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<!--
Configure session id management
-->
<Set name="sessionIdManager">
<New class="com.ovea.jetty.session.redis.RedisSessionIdManager">
<Arg>
<Ref id="Server"/>
</Arg>
<Arg>session/redis</Arg>
<!-- time interval to check for expired sessions in redis cache, in milliseconds. Defaults to 1 min -->
<Set name="scavengerInterval">30000</Set>
<!-- cluster node name -->
<Set name="workerName">
<SystemProperty name="jetty.node" default="node1"/>
</Set>
</New>
</Set>
<!--
Provides a Redis Pool for session management on server and each webapp
-->
<New class="org.eclipse.jetty.plus.jndi.Resource">
<Arg>session/redis</Arg>
<Arg>
<New class="redis.clients.jedis.JedisPool">
<Arg>
<New class="org.apache.commons.pool.impl.GenericObjectPool$Config">
<Set type="int" name="minIdle">5</Set>
<Set type="int" name="maxActive">15</Set>
<Set type="boolean" name="testOnBorrow">true</Set>
</New>
</Arg>
<Arg>127.0.0.1</Arg>
<Arg type="int">6379</Arg>
</New>
</Arg>
</New>
</Configure>
In each web application context file using session clustering (i.e. in WEB-INF/jetty-env.xml):
<Configure id="webappContext" class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="contextPath">/webapp1</Set>
<Set name="sessionHandler">
<New class="org.eclipse.jetty.server.session.SessionHandler">
<Arg>
<New class="com.ovea.jetty.session.redis.RedisSessionManager">
<Arg>session/redis</Arg>
<Arg>
<New class="com.ovea.jetty.session.serializer.JsonSerializer"/>
</Arg>
<!-- set the interval in seconds to force session persistence event if it didn't changed. Default to 60 seconds -->
<Set name="saveInterval">20</Set>
<!-- set the cookie domain -->
<Set name="sessionDomain">127.0.0.1</Set>
<!-- set the cookie path -->
<Set name="sessionPath">/</Set>
<!-- set the cookie max age in seconds. Default is -1 (no max age). 1 day = 86400 seconds -->
<Set name="maxCookieAge">86400</Set>
<!-- set the interval in seconds to refresh the cookie max age. Default to 0. This number should be lower than the session expirity time. -->
<Set name="refreshCookieAge">300</Set>
</New>
</Arg>
</New>
</Set>
</Configure>
Note: Jetty's default for maxCookieAge is -1 and as per my tests, setting it to a too short value may cause issues in session retrieval.
Controlling session serialization
By default, session attributes are serialized using XStream, but this is clearly the worst serializer and you must make sure that you configure the serializer according to your needs. If you have small sessions with simple types, consider the JsonSerializer. If you have complexe objects but all serializable, you can consider the JbossSerializer. You can also create your own ones byt implementing the Serializer class of a provided skeleton (see examples here).
Here is the list of provided Serializer:
com.ovea.jetty.session.serializer.JsonSerializer
com.ovea.jetty.session.serializer.JdkSerializer
com.ovea.jetty.session.serializer.XStreamSerializer
com.ovea.jetty.session.serializer.JBossSerializer
session/redis
Debugging
If you need to troobleshoot something, you can put Jetty in DEBUG mode and see the traces from RedisSessionManager and RedisSessionIdManager.
Also, with Redis you have the ability to monitor all the calls. Simply issue in a command-line:
redis-cli monitor
To see all Redis requests going to the Redis server. If you are using a String serializer such as XStream of Json, you'll be able to see all your session attributes into.
Versions & Compatibility
The latest release (>= 2.1.ga) must be used with at least these dependencies:
com.ovea:jetty-session-redis:2.1.ga:serialjson
org.eclipse.jetty.aggregate:jetty-all:8.0.2.v20111006
org.mortbay.jetty:servlet-api:3.0.20100224
redis.clients:jedis:2.0.0
commons-pool:commons-pool:1.5.6
Authors and help
Mathieu Carbou mail | blog | website
https://github.com/Ovea/jetty-session-redis
分享到:
相关推荐
码头Redis会议一个使用Redis作为后端的Jetty 9.4.x SessionDataMap实现。 从。 还Apache许可的的会话序列化代码使用MIT许可的Jedis作为Redis的客户端。
eclipse jetty插件,从...下载run-jetty-run.zip文件,解压后再编写个links文件丢到eclipse的dropins目录下即可,省去了使用eclipse update方式安装的麻烦。 link文件样例如: path=d:\\eclipse_plugins\\run-jetty-run
赠送jar包:jetty-util-6.1.26.jar; 赠送原API文档:jetty-util-6.1.26-javadoc.jar; 赠送源代码:jetty-util-6.1.26-sources.jar; 赠送Maven依赖信息文件:jetty-util-6.1.26.pom; 包含翻译后的API文档:jetty-...
赠送jar包:jetty-http-9.4.11.v20180605.jar; 赠送原API文档:jetty-http-9.4.11.v20180605-javadoc.jar; 赠送源代码:jetty-http-9.4.11.v20180605-sources.jar; 赠送Maven依赖信息文件:jetty-...
run-jetty-run 1.3.5(Nightly) 在eclipse 4.5.2中安装jetty插件,然后提取plugins和features目录中的相关文件,打包做成可用link方式安装,省去更换eclipse版本时需要重新下载的问题。 安装方法为新加一个run-jetty...
jetty-all-9.4.47.v20220610-uber.jar
赠送jar包:jetty-server-8.1.8.jar; 赠送原API文档:jetty-server-8.1.8-javadoc.jar; 赠送源代码:jetty-server-8.1.8-sources.jar; 赠送Maven依赖信息文件:jetty-server-8.1.8.pom; 包含翻译后的API文档:...
jetty-security-9.4.8.v20171121.jar,jetty-io-9.4.8.v20171121.jar,jetty-continuation-9.4.8.v20171121.jar,jetty-client-9.4.8.v20171121.jar,jetty-jmx-9.4.8.v20171121.jar,jetty-plus-9.4.8.v20171121....
赠送jar包:jetty-security-9.3.19.v20170502.jar; 赠送原API文档:jetty-security-9.3.19.v20170502-javadoc.jar; 赠送源代码:jetty-security-9.3.19.v20170502-sources.jar; 赠送Maven依赖信息文件:jetty-...
赠送jar包:jetty-server-8.1.8.v20121106.jar; 赠送原API文档:jetty-server-8.1.8.v20121106-javadoc.jar; 赠送源代码:jetty-server-8.1.8.v20121106-sources.jar; 赠送Maven依赖信息文件:jetty-server-8.1.8...
赠送jar包:jetty-io-9.4.8.v20171121.jar; 赠送原API文档:jetty-io-9.4.8.v20171121-javadoc.jar; 赠送源代码:jetty-io-9.4.8.v20171121-sources.jar; 赠送Maven依赖信息文件:jetty-io-9.4.8.v20171121.pom;...
赠送jar包:jetty-webapp-9.3.19.v20170502.jar; 赠送原API文档:jetty-webapp-9.3.19.v20170502-javadoc.jar; 赠送源代码:jetty-webapp-9.3.19.v20170502-sources.jar; 赠送Maven依赖信息文件:jetty-webapp-...
赠送jar包:jetty-io-9.4.43.v20210629.jar; 赠送原API文档:jetty-io-9.4.43.v20210629-javadoc.jar; 赠送源代码:jetty-io-9.4.43.v20210629-sources.jar; 赠送Maven依赖信息文件:jetty-io-9.4.43.v20210629....
赠送jar包:jetty-util-6.1.26.jar; 赠送原API文档:jetty-util-6.1.26-javadoc.jar; 赠送源代码:jetty-util-6.1.26-sources.jar; 赠送Maven依赖信息文件:jetty-util-6.1.26.pom; 包含翻译后的API文档:jetty-...
赠送jar包:jetty-util-9.4.43.v20210629.jar; 赠送原API文档:jetty-util-9.4.43.v20210629-javadoc.jar; 赠送源代码:jetty-util-9.4.43.v20210629-sources.jar; 赠送Maven依赖信息文件:jetty-util-9.4.43.v...
赠送jar包:jetty-sslengine-6.1.26.jar; 赠送原API文档:jetty-sslengine-6.1.26-javadoc.jar; 赠送源代码:jetty-sslengine-6.1.26-sources.jar; 赠送Maven依赖信息文件:jetty-sslengine-6.1.26.pom; 包含...
赠送jar包:jetty-sslengine-6.1.26.jar; 赠送原API文档:jetty-sslengine-6.1.26-javadoc.jar; 赠送源代码:jetty-sslengine-6.1.26-sources.jar; 赠送Maven依赖信息文件:jetty-sslengine-6.1.26.pom; 包含...
赠送jar包:jetty-server-8.1.8.jar; 赠送原API文档:jetty-server-8.1.8-javadoc.jar; 赠送源代码:jetty-server-8.1.8-sources.jar; 赠送Maven依赖信息文件:jetty-server-8.1.8.pom; 包含翻译后的API文档:...
赠送jar包:jetty-6.1.26.jar; 赠送原API文档:jetty-6.1.26-javadoc.jar; 赠送源代码:jetty-6.1.26-sources.jar; 赠送Maven依赖信息文件:jetty-6.1.26.pom; 包含翻译后的API文档:jetty-6.1.26-javadoc-API...
jetty-http-7.4.2.v20110526.jar jetty-http 服务jar包