What should I do if I want to deploy Play Framework app to multiple servers?

这一生的挚爱 提交于 2019-12-10 19:29:38

问题


If I would like to deploy my application using Play Framework 2.x to multiple servers, what are the things I need to care about?

  1. If I am using (built-in) sessions, will it be available to all the nodes since they are stored in browser side?

  2. How can I share variables application-wide except for storing them in the database?


回答1:


When putting a Play application in production to multiple server nodes, you should check following steps:

  • Ensure the application secret (that encrypts and signs the session cookie) IS THE SAME on every node, as you won't be able to which node will send the HTTP response.
  • Ensure that you did not use the built in cache system (ehcache) to store user specific information (as the cache is stored in server's memory).

That's all...

So to answer your other points:

  1. If you're using (built-in) sessions, information stored in the session cookie will be available to every server node (as it comes from the client). Just remember that a cookie is limited to 4kb in some old browsers (IE6), so be carefull about the quantity of information you put in the session.
  2. If you want to share other application wide variables:

    • if the information is user specific, you can also store them on the session, or in another cookie. For instance if you want to save current user's theme: response().setCookie("theme", "blue");. Then you can retrieve the stored information with Http.Request.current().cookies.get("theme"). You can have a deeper look into play sessions and cookie.

    • If you want to share other variables across multiple nodes, you'll have to use distributed cache solutions like memcached or, your database like you suggested.

If not already done, you should have a look into how to deploy play to production



来源:https://stackoverflow.com/questions/29624216/what-should-i-do-if-i-want-to-deploy-play-framework-app-to-multiple-servers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!