如何在Spring Boot中设置ActiveMQ端口? [英] How to set ActiveMQ port in Spring Boot?

查看:394
本文介绍了如何在Spring Boot中设置ActiveMQ端口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一台服务器上运行了两个Spring Boot应用程序。两者都使用嵌入式ActiveMQ JMS。我希望每个应用程序都有单独的JMS实例。如何为每个端口设置端口?有没有像 spring.activemq.port 这样的属性?
运行第二个应用程序时,出现以下预期错误:

I have two Spring Boot applications running on one server. Both use embedded ActiveMQ JMS. I want to have separate JMS instance for each application. How could I set the port for each of them? Is there any property like spring.activemq.port? When I run second application I get the following expected error:

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 文件中,

I have same issue, two SpringBoot process and I want to send messages through the ActiveMQ. First I got it working starting another process with the ActiveMQ, and configuring both SpringBoot process into their application.properties files with:

spring.activemq.broker-url = tcp://localhost:61616

在此配置中,您告诉Springboot连接到外部ActiveMq服务。此方法有效,但随后我需要先启动ActiveMQ ,然后执行Springboot过程。在某些页面上,我读到了这一定是在生产环境中使用的方式。

Whit this configuration you tell Springboot to connect to a external ActiveMq service. This works, but then I need to first start the ActiveMQ and after my Springboot process. In some page I have read this must be the way to use at production environments.

另一种解决方案是在其中一个SpringBoot流程中使用嵌入式JMS支持。您需要一种配置ActiveMQ代理服务的方式,以在一个Springboot进程中侦听连接。您可以通过添加Broker bean来做到这一点:

Another solution is to use the embedded JMS support at one of the SpringBoot process, for this way you need to configure the ActiveMQ broker service listening for connections in one Springboot process. You can do this adding a 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侦听其他进程连接。

Now this SpringBoot process with this bean do not need the previous configuration at the application.properties, and this will be the first process to start, in order to have the ActiveMQ listening for other process connections.

另一个Springboot进程仍需要在 application.properties 进行配置,以连接到第一个进程创建的ActiveMq。

The other Springboot process still need to have the configuration at the application.properties in order to connect to the ActiveMq created by the first process.

希望它会有所帮助您。
最好的问候。

Hope it helps you. Best regards.

这篇关于如何在Spring Boot中设置ActiveMQ端口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆