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.
Igorock
  • 2,691
  • 6
  • 28
  • 39

3 Answers3

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.

Eidansoft
  • 157
  • 2
  • 9
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.

gtonic
  • 2,295
  • 1
  • 24
  • 32
  • 1
    when I do this I get: Could not connect to broker URL: tcp://localhost:61616. Reason: java.net.ConnectException: Connection refused: connect – Igorock Mar 08 '17 at 21:15
  • 1
    I think this property is used for setting remote JMS, not for changing the url of embedded – Igorock Mar 08 '17 at 21:47
  • Can you provide the settings you are using for each application? There are several ports which might be in conflict. – gtonic Mar 09 '17 at 05:46
  • in application.properties I have only server.port=8091 for the first server and server.port=8093 for the second – Igorock Mar 09 '17 at 19:40
1

spring.activemq.broker-url

Including the port according to spring boot properties

rob
  • 212
  • 3
  • 8