How to set ActiveMQ port in Spring Boot?
Asked Answered
S

3

7

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.
Swint answered 8/3, 2017 at 20:45 Comment(0)
B
7

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.

Bodily answered 21/6, 2017 at 7:26 Comment(0)
D
2

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.

Dotard answered 8/3, 2017 at 21:0 Comment(4)
when I do this I get: Could not connect to broker URL: tcp://localhost:61616. Reason: java.net.ConnectException: Connection refused: connectSwint
I think this property is used for setting remote JMS, not for changing the url of embeddedSwint
Can you provide the settings you are using for each application? There are several ports which might be in conflict.Dotard
in application.properties I have only server.port=8091 for the first server and server.port=8093 for the secondSwint
L
1

spring.activemq.broker-url

Including the port according to spring boot properties

Lalitta answered 8/3, 2017 at 21:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.