Should I use just one Session in my application based on HornetQ?

别等时光非礼了梦想. 提交于 2019-12-01 07:28:26

问题


In application based on HornetQ engine I intend to create multiple Producers and Consumers. I have learned, that I should reuse resources as much as possible thanks to this page.

Does that mean, that for my application I should crate one and exactly one ConnectionFactory, one Connection, one Session and then (using this Session object) creating as many Producers/Consumers as I want?

That shouldn't be hard, but I'm not sure if this is the proper approach.


回答1:


The best rule of thumb for minimum resource usage is to use the fewest constructs as possible while remaining thread safe. Accordingly:

  1. Connection Factories are thread safe: One per JMS server (or one per JMS server per destination type for topics and queues)
  2. Connections are thread safe: Depending on the application architecture, you may be able to use one connection, but I would not bend over backwards to do this.
  3. Sessions and all constructs below the session are NOT thread safe: You will need one session per concurrent thread (or per transaction if you think about it that way).

Based on that, hopefully you can strike a balance between an elegant architecture and low resource utilization.



来源:https://stackoverflow.com/questions/4335895/should-i-use-just-one-session-in-my-application-based-on-hornetq

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