3

I'm trying to refactor some legacy code to use Spring to handle the jms connections to a mainframe service. I need to connect create a temporary topic for the mainframe service reply and set that as the message.setJMSReplyTo(replyTo); in the message before I send the message.

Can anyone provide examples of this? I have not found anything in the documentation that allows you to get to the low level jms objects such as the session or TopicConnection in order to create a temporary topic.

4

2 回答 2

1

如果您需要使用 对 JMS API 进行低级访问JmsTemplate,那么您需要使用 JmsTemplate 的execute(...)方法之一。其中最简单的是execute(SessionCallBack)SessionCallback 为您提供 JMS Session 对象。有了它,您可以调用createTemporaryQueue()createTemporaryTopic()。不过,您可能可以使用其他 execute() 方法之一为您完成一些初始工作,例如这个

于 2009-10-19T23:18:30.383 回答
1

我能够在 Spring Boot 应用程序中使用以下代码动态创建队列:

在 Application.java 中

@Bean 
public ConnectionFactory jmsFactory()
{
    ActiveMQConnectionFactory amq = new ActiveMQConnectionFactory()

    amq.setBrokerURL("tcp://somehost");

    return amq;
}

@Bean 
public JmsTemplate myJmsTemplate()
{
    JmsTemplate jmsTemplate = new JmsTemplate(jmsFactory());

    jmsTemplate.setPubSubDomain(false);
    return jmsTemplate;
}

然后在另一个动态创建队列的类中:

@Component
public class Foo {
    @Autowired
    private ConnectionFactory jmsFactory;

    public void someMethod () {
        DefaultMessageListenerContainer messageListener = new DefaultMessageListenerContainer();

        messageListener.setDestinationName("queueName");
        messageListener.setConnectionFactory(jmsFactory);
        messageListener.setMessageListener(new Consumer("queueName"));
        messageListener.setPubSubDomain(false);
        messageListener.initialize();
        messageListener.start();
    }
}
于 2015-02-04T17:22:50.623 回答