Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set ActiveMQ port in Spring Boot?

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.
like image 578
Igorock Avatar asked Mar 08 '17 20:03

Igorock


People also ask

What is ActiveMQ default port?

ActiveMQ's default port is 61616.


1 Answers

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.

like image 167
Eidansoft Avatar answered Oct 24 '22 05:10

Eidansoft