Jms在升级到Spring Boot 3之后不起作用(以及从javax到jakarta的ConnectionFactory)

huangapple go评论78阅读模式
英文:

Jms not working after update to spring boot 3 (and ConnectionFactory from javax to jakarta)

问题

在从SpringBoot v.2.5.5升级到v3.1.0后,需要将ConnectionFactory也从javax.jms.ConnectionFactory更新为jakarta.jms.ConnectionFactory
我没有改变其他任何东西。不幸的是,现在我遇到了这样的错误:
ERROR - 无法刷新用于目标 'tServerEvent' 的JMS连接 - 重试使用FixedBackOff{interval=5000, currentAttempts=0, maxAttempts=unlimited}。原因:无法连接到经纪人URL:tcp://localhost:61616。原因:java.net.ConnectException:连接被拒绝:没有进一步的信息

我进行了调查,并与旧的javax.ConnectionFactory进行了比较,似乎它们的默认brokerUrl不同

对于javax.jms.ConnectionFactory,它是:vm://localhost?broker.persistent=false
对于jakarta.jms.ConnectionFactory,它是:tcp://localhost:61616

即使我手动设置经纪人URL,像这样:

spring:
  activemq:
    broker-url: vm://localhost?broker.persistent=false

它仍然不起作用,错误是:原因:无法创建传输。原因:java.io.IOException:未识别的传输方案:[vm]

我不知道为什么jakarta.ConnectionFactory和旧的javax.ConnectionFactory的默认brokerUrl不同,也不知道如何成功运行我的应用程序。
如果您对我有一些提示,我将不胜感激。

以下是带有ConnectionFactory的JmsListenerContainerFactory Bean的代码:

import jakarta.jms.ConnectionFactory;
import org.springframework.boot.autoconfigure.jms.DefaultJmsListenerContainerFactoryConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jms.annotation.EnableJms;
import org.springframework.jms.config.DefaultJmsListenerContainerFactory;
import org.springframework.jms.config.JmsListenerContainerFactory;

@Configuration
@EnableJms
public class JmsConfig {

    @Bean
    public JmsListenerContainerFactory<?> myFactory(ConnectionFactory connectionFactory, DefaultJmsListenerContainerFactoryConfigurer configurer) {
        DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
        configurer.configure(factory, connectionFactory);
        return factory;
    }

}
英文:

After update from SpringBoot v.2.5.5 to v3.1.0 it was necessary to update also ConnectionFactory from javax.jms.ConnectionFactory to jakarta.jms.ConnectionFactory.
I haven't changed anything else. Unfortunately now I'm getting an errors like this:
ERROR - Could not refresh JMS Connection for destination &#39;tServerEvent&#39; - retrying using FixedBackOff{interval=5000, currentAttempts=0, maxAttempts=unlimited}. Cause: Could not connect to broker URL: tcp://localhost:61616. Reason: java.net.ConnectException: Connection refused: no further information

I investigated it and compared with the old javax.ConnectionFactory and it seems that default brokerUrl for them is different

for javax.jms.ConnectionFactory it was : vm://localhost?broker.persistent=false
for jakarta.jms.ConnectionFactory it is : tcp://localhost:61616

Even if I manually set broker url, like this:

spring:
  activemq:
    broker-url: vm://localhost?broker.persistent=false

it is not working still and the error is: Cause: Could not create Transport. Reason: java.io.IOException: Transport scheme NOT recognized: [vm]

I don't know why the default brokerUrl is different for jakarta.ConnectionFactory and old javax.ConnectionFactory and don't know how can I run my application succesfullt.
I would appreciate if you have some tips for me.

And here is code with JmsListenerContainerFacroty Bean with ConnectionFactory:

import jakarta.jms.ConnectionFactory;
import org.springframework.boot.autoconfigure.jms.DefaultJmsListenerContainerFactoryConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jms.annotation.EnableJms;
import org.springframework.jms.config.DefaultJmsListenerContainerFactory;
import org.springframework.jms.config.JmsListenerContainerFactory;

@Configuration
@EnableJms
public class JmsConfig {

    @Bean
    public JmsListenerContainerFactory&lt;?&gt; myFactory(ConnectionFactory connectionFactory, DefaultJmsListenerContainerFactoryConfigurer configurer) {
        DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
        configurer.configure(factory, connectionFactory);
        return factory;
    }

}

答案1

得分: 5

对于 ActiveMQ,在 Spring Boot 3.0 中已被移除,因为它不支持 JMS 3.0(jakarta.jms.* APIs)。Spring Boot 3.1 恢复了对自动配置 ActiveMQ 客户端的支持。嵌入式代理支持尚未恢复,因为ActiveMQ的代理尚未支持 JMS 3.0。

要在 Spring Boot 3.1 中使用 ActiveMQ,您将需要使用外部代理,就像Spring Boot 的 ActiveMQ 烟雾测试所做的那样。

英文:

Support for ActiveMQ was removed in Spring Boot 3.0 as is did not support JMS 3.0 (the jakarta.jms.* APIs). Spring Boot 3.1 restored support for auto-configuring an ActiveMQ client. Embedded broker support has not been restored as ActiveMQ's broker does not yet support JMS 3.0.

To use ActiveMQ will Spring Boot 3.1, you will have to use an external broker as Spring Boot's ActiveMQ smoke test does.

huangapple
  • 本文由 发表于 2023年6月1日 16:43:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/76380103.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定