【发布时间】:2019-01-13 10:09:43
【问题描述】:
我希望我的 Spring Boot 应用程序能够启动,无论它是否可以连接到 JMS。我有这个最小的例子:
@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";
}
}
}
当application.properties 包含:
spring.activemq.broker-url=tcp://non-existing-broker:61616
我可以从helloWorld 端点获得响应。当我将属性更改为:
spring.activemq.broker-url=failover:(tcp://non-existing-broker:61616)
应用程序不断尝试连接到代理,我无法从我的 REST 端点获得响应。
请指教,如何在不等待 ActiveMQ 故障转移传输成功的情况下运行应用程序。
【问题讨论】:
-
我刚试过你的代码。应用程序启动并且rest端点是可达的,
-
@pvpkiran 请再试一次。在日志中我收到警告:
Failed to connect to [tcp://non-existing-broker:61616] after: 10 attempt(s) continuing to retry.Executingcurl http://localhost:8080/我收到Connection refused。 -
@pvpkiran 看起来您没有使用故障转移传输。请确保您在代理网址前有
failover:(...。我希望它可以在没有它的情况下使用故障转移传输:)
标签: java spring spring-boot activemq spring-jms