我应该在基于HornetQ的应用程序中只使用一个Session吗? [英] Should I use just one Session in my application based on HornetQ?
问题描述
在基于HornetQ引擎的应用程序中,我打算创建多个生产者和消费者。
我已经了解到,由于此页,我应该尽可能多地重用资源。
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.
这是否意味着,对于我的应用程序,我应该创建一个且一个ConnectionFactory,一个Connection,一个Session然后(使用此Session对象)创建尽可能多的Producers /消费者我想要的?
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.
推荐答案
最小资源使用的最佳经验法则是尽可能使用最少的结构,同时保持线程安全。因此:
The best rule of thumb for minimum resource usage is to use the fewest constructs as possible while remaining thread safe. Accordingly:
- 连接工厂是线程安全的:每个JMS服务器一个(或每个目标类型的主机和队列每个JMS服务器一个)
- 连接是线程安全的:根据应用程序架构,您可以使用一个连接,但我不会向后弯腰来执行此操作。
- 会话下面的会话和所有构造都是 NOT 线程安全:每个并发线程需要一个会话(如果按这种方式考虑,则需要每个事务)。
- Connection Factories are thread safe: One per JMS server (or one per JMS server per destination type for topics and queues)
- 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.
- 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.
这篇关于我应该在基于HornetQ的应用程序中只使用一个Session吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!