在Spring中创建临时JMS jms主题

发布于 2024-08-08 04:09:35 字数 215 浏览 2 评论 0原文

我正在尝试重构一些遗留代码以使用 Spring 处理与大型机服务的 jms 连接。我需要连接为大型机服务回复创建一个临时主题,并将其设置为消息中的 message.setJMSReplyTo(replyTo);,然后再发送消息。

谁能提供这方面的例子吗?我在文档中没有找到任何允许您访问低级别 jms 对象(例如会话或 TopicConnection)以创建临时主题的内容。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

楠木可依 2024-08-15 04:09:35

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

If you need low-level access to the JMS API using JmsTemplate, then you need to use one of JmsTemplate's execute(...) methods. The simplest of these is execute(SessionCallBack), where the SessionCallback provides you with the JMS Session object. With that, you can call createTemporaryQueue() or createTemporaryTopic(). You can probably use one of the other execute() methods do some of the initial work for you, though, such as this one.

若水般的淡然安静女子 2024-08-15 04:09:35

我能够在 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();
    }
}

I was able to create a queue dynamically using the following code in a Spring Boot app:

In 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;
}

Then in another class which creates the queue dynamically:

@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();
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文