如何在 Spring Boot 中设置 ActiveMQ 端口?
How to set ActiveMQ port in Spring Boot?
我在一台服务器上有两个 Spring 引导应用程序 运行ning。两者都使用嵌入式 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.
您可以使用 spring.activemq.broker-url
属性 配置代理 url,例如将其设置为 spring.activemq.broker-url=tcp://localhost:61616
。
有关可用属性的综合参考,您可以查看此 reference。
spring.activemq.broker-url
包括端口
我有同样的问题,两个 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
希望对你有帮助。
最好的问候。
我在一台服务器上有两个 Spring 引导应用程序 运行ning。两者都使用嵌入式 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.
您可以使用 spring.activemq.broker-url
属性 配置代理 url,例如将其设置为 spring.activemq.broker-url=tcp://localhost:61616
。
有关可用属性的综合参考,您可以查看此 reference。
spring.activemq.broker-url
包括端口我有同样的问题,两个 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
希望对你有帮助。 最好的问候。