How to set ActiveMQ port in Spring Boot?

2020-07-11 07:35发布

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.

3条回答
淡お忘
2楼-- · 2020-07-11 07:40

spring.activemq.broker-url

Including the port according to spring boot properties

查看更多
一夜七次
3楼-- · 2020-07-11 07:41

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

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.

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;
}

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.

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.

查看更多
劳资没心,怎么记你
4楼-- · 2020-07-11 07:51

You can configure the broker url using the spring.activemq.broker-url property, e.g. set it to spring.activemq.broker-url=tcp://localhost:61616.

For a comprehensive reference of available properties you can check out this reference.

查看更多
登录 后发表回答