开发者

MongoDB based session storage for Tomcat6

Is there anyway to user MongoDB as a central session storage f开发者_JS百科or Tomcat6? If so, could we have a cluster of tomcat servers reading session data from MongoDB so that the cluster could be dinamically resized (adding more boxes on the fly) without the need of sticky sessions?


I think I found what I was looking for.

https://github.com/dawsonsystems/Mongo-Tomcat-Sessions

If anyone has used it in production, I would love to hear your experiences.


Tomcat/J2EE sessions have a getId() method which returns the session ID for the current user. You can certainly use this as a key into a sessions collection in MongoDB, and store any data you'd like.

I'm not aware of any pre-built tools to integrate specifically with Tomcat 6, but that doesn't mean they don't exist. But this is a fairly straightforward task, it might be simplest just to write your own DAO to access session data given an HttpSession or HttpServletRequest.

If your session data is the only shared state you maintain, then moving it to MongoDB (or to any off-appserver database or tool) will enable you to scale like you propose. If you have other state maintained on the application servers, then you will need to determine how to move that off of the app servers and onto a shared resource.


I think there is a better way using MongoDD to store sessions, just using Servlet-Api functions and no proprietary Appserver-features.

  1. First of all you need to create your own implementation of an HttpSession based on a Map for storeing attributes
  2. You need to create an implementation of HttpServletRequest (using HttpServletRequest Wrapper) that overwrites getSession-method and returns your implementation
  3. You need to create a filter which replaces the given HttpRequest against your created and do the MongoDB-Handling to load and store the attribute-map

You find some code-samples (sadly in german language) here: http://mibutec.wordpress.com/2013/09/23/eigenes-session-handling-in-webapplikationen/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜