spring - 如何指示 JMSTemplate.receive() 应该使用 DurableSubscriber

标签 spring jms spring-jms ems

我想在不使用 xml 配置的情况下执行此操作。我正在玩弄 Spring JMS,看它是否满足我的需求。无论如何使用

进行同步接收
JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory);
jmsTemplate.receive() 

因此它等同于纯 JMS 调用:

MessageConsumer consumer = session.createDurableSubscriber(topic, "durable name");
Message message = consumer.receive();

无需通过xml配置?

最佳答案

试试这个,但你打算怎么调用它?

  //Create connection facotry ..in this case JndiObjectFactoryBean because i am looking up a JNDI
  org.springframework.jndi.JndiObjectFactoryBean connectionFactory = new JndiObjectFactoryBean();
  connectionFactory.setJndiName(jndiName);
  connectionFactory.setJndiTemplate(jndiTemplate);

  org.springframework.jms.core.JmsTemplate template = new org.springframework.jms.core.JmsTemplate();
  template.setConnectionFactory(connectionFactory)
  template.setPubSubDomain(false);

  Message message = template.receive();

更多信息请查看 http://static.springsource.org/spring/docs/3.1.x/javadoc-api/org/springframework/jms/core/JmsTemplate.html#receive%28%29

http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/jms.html#jms-receiving-sync

关于spring - 如何指示 JMSTemplate.receive() 应该使用 DurableSubscriber,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10506538/

相关文章:

ssl - 1 路 SSL 与 MQIPT 和 tomcat docker

java - 无法 Autowiring 。找不到 bean 'here name' 类型

java - Spring JDBC 事务管理器

java - Spring MVC @RequestMapping 不返回任何内容,只需关闭

java - Jms 如何知道订阅者不再活着

java - Camel JMS : how to configure custom message listener when connecting to a topic

java - 当我运行 Spring Boot 应用程序时,出现以下错误。我使用的是 Spring Boot 版本 2.3.1

java - 事务生产者 session 的确认模式

tomcat - 部署在同一 tomcat 中的跨应用程序之间的 JMS 消息传递

activemq - 无法刷新目标 'queue://inventorydsDestination' 的 JMS 连接 - 将在 5000 毫秒后重试。原因: AOP configuration seems to be invalid