Java ActiveMQ故障转移传输失败时,Spring引导应用程序不会启动
我希望我的Spring启动应用程序启动,不管它是否可以连接到JMS。我有一个简单的例子:Java ActiveMQ故障转移传输失败时,Spring引导应用程序不会启动,java,spring,spring-boot,activemq,spring-jms,Java,Spring,Spring Boot,Activemq,Spring Jms,我希望我的Spring启动应用程序启动,不管它是否可以连接到JMS。我有一个简单的例子: @SpringBootApplication @EnableJms public class JmsActivemqFailoverApplication { public static void main(String[] args) { SpringApplication.run(JmsActivemqFailoverApplication.class, args);
@SpringBootApplication
@EnableJms
public class JmsActivemqFailoverApplication {
public static void main(String[] args) {
SpringApplication.run(JmsActivemqFailoverApplication.class, args);
}
@Component
public static class JmsReceiver {
@JmsListener(destination = "inbox")
public void receive(Message message) {
System.out.println("Received <" + message + ">");
}
}
@RestController
public static class HelloWorldController {
@GetMapping("/")
public String helloWorld() {
return "Hello world";
}
}
}
@springboot应用程序
@使能JMS
公共类JmsActivemqFailoverApplication{
公共静态void main(字符串[]args){
run(jmsativemqfailoverapplication.class,args);
}
@组成部分
公共静态类JmsReceiver{
@JmsListener(destination=“收件箱”)
公共无效接收(消息){
系统输出打印项次(“收到”);
}
}
@RestController
公共静态类HelloWorldController{
@GetMapping(“/”)
公共字符串helloWorld(){
返回“你好世界”;
}
}
}
当application.properties
包含以下内容时:
spring.activemq.broker-url=tcp://non-existing-broker:61616
我可以从helloWorld
端点获得响应。当我将属性更改为:
spring.activemq.broker url=故障转移:(tcp://non-existing-broker:61616)
应用程序一直试图连接到代理,我无法从REST端点获得响应
请给出建议,如何让应用程序在不等待ActiveMQ故障转移传输成功的情况下运行
示例代码位于实现此目的的一种方法是:
spring.JMS.listener.auto startup=false禁用JMS容器的自动启动
@Component
public class JmsStarter implements ApplicationRunner {
private final JmsListenerEndpointRegistry jmsRegistry;
public JmsStarter(JmsListenerEndpointRegistry jmsRegistry) {
this.jmsRegistry = jmsRegistry;
}
@Override
public void run(ApplicationArguments args) {
for (MessageListenerContainer listenerContainer : jmsRegistry.getListenerContainers()) {
listenerContainer.start();
}
}
}
我刚试过你的密码。应用程序启动且rest端点可访问,@pvpkiran请重试。在日志中,我收到一条警告:
无法连接到[tcp://non-existing-broker:61616]之后:10次尝试继续重试。
执行curlhttp://localhost:8080/
我发现连接被拒绝
@pvpkiran看起来您没有使用故障转移传输。请确保在代理url之前有故障转移:(…
。我希望它能够与故障转移传输一起工作,因为它在没有它的情况下也能工作:)Ya。你是对的。我错过了故障切换,我正要建议相同的解决方案。对于数据源,springboot中有一个类似于spring.datasource.continue on error=true的属性。但是jms没有这样的东西。您可以在springboot中创建一个bug