java - Spring JMS 定义多个目的地

标签 java spring jms jndi spring-jms

spring documentation说:

Destinations, as ConnectionFactory instances, are JMS administered objects that you can store and retrieved in JNDI. When configuring a Spring application context, you can use the JNDI JndiObjectFactoryBean factory class or to perform dependency injection on your object’s references to JMS destinations.

However, this strategy is often cumbersome if there are a large number of destinations in the application or if there are advanced destination management features unique to the JMS provider.

问题是:

当我的申请中有大量目的地时如何继续?

使用上面提到的策略,我必须定义:

  • Jndi模板
  • JndiDestinationResolver
  • JndiObjectFactoryBean
  • 缓存连接工厂
  • JmsTemplate

对于每个目的地。

所以如果我有 20 个队列,我就必须定义 100 个这样的 bean...

最佳答案

Spring 文档中的注释注释了“对目标端点使用 JNDI”与“对目标端点不使用 JNDI”。那么就您而言 - 您的目的地是否存储在 JNDI 中?如果您不需要使用它,请忘记它。仅从 JNDI 加载 ConnectionFactory(一个对象)或从头开始创建它。

这样您就不必为每个目标分配一个 Spring bean。您可以只有一个 Java“消费者 bean”,然后它使用 JmsTemplate。我猜您的连接工厂是相同的,因此只有一个 new JmsTemplate(connectionFactory)。然后根据需要进行createSession/createConsumer等操作。

关于java - Spring JMS 定义多个目的地,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55460921/

相关文章:

java - 如何打开一个新的具有特定光标偏移位置的eclipse编辑器

Java Spring : How to specify resource path's correctly in application. 属性?

glassfish - 一些请求后,与队列 createConnection 的 JMS 连接失败

java - Camel 组件定义: What is the difference between componentProperties and properties?

java - Excel 中的 DDE 信息

java - Play框架打包源文件

java - 使 EditText 字段在 Android 中只接受字母和空格

spring - 遍历jsp中的PagedListHolder

java - 覆盖 Spring 数据 JPA id 注释。

java - session 事务在哪里有用?