我有两个 Spring Boot 应用程序在一台服务器上运行。两者都使用嵌入式 ActiveMQ JMS。我想为每个应用程序提供单独的 JMS 实例。我怎么能为他们每个人设置端口?是否有类似 spring.activemq.port
的属性?
当我运行第二个应用程序时,出现以下预期错误:
Failed to start JMX connector Cannot bind to URL [rmi://localhost:1099/jmxrmi]: javax.naming.NameAlreadyBoundException: jmxrmi [Root exception is java.rmi.AlreadyBoundException: jmxrmi]. Will restart management to re-create JMX connector, trying to remedy this issue.
最佳答案
我有同样的问题,两个 SpringBoot 进程,我想通过 ActiveMQ 发送消息。 首先,我使用 ActiveMQ 启动另一个进程,并将两个 SpringBoot 进程配置到它们的 application.properties 文件中:
spring.activemq.broker-url = tcp://localhost:61616
通过此配置,您可以告诉 Springboot 连接到外部 ActiveMq 服务。这行得通,但我需要先 start the ActiveMQ在我的 Springboot 过程之后。在某些页面上,我读到这必须是在生产环境中使用的方式。
另一种解决方案是在一个 SpringBoot 进程中使用嵌入式 JMS 支持,为此您需要配置 ActiveMQ 代理服务在一个 Springboot 进程中监听连接。您可以添加 Broker bean 来执行此操作:
@Bean
public BrokerService broker() throws Exception {
final BrokerService broker = new BrokerService();
broker.addConnector("tcp://localhost:61616");
broker.addConnector("vm://localhost");
broker.setPersistent(false);
return broker;
}
现在这个带有这个 bean 的 SpringBoot 进程不需要之前在 application.properties 的配置,这将是第一个启动的进程,以便 ActiveMQ 监听其他进程连接.
另一个 Springboot 进程仍然需要在 application.properties 中进行配置,以便连接到第一个进程创建的 ActiveMq。
希望对你有帮助。 最好的问候。
关于java - 如何在 Spring Boot 中设置 ActiveMQ 端口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42681595/