gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 06:20:26 25 4
gpt4 key购买 nike

我想在不使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com