11

I'm working on a Spring Boot project at the moment, this text keeps being printed to the console every second for thirty seconds before stopping.

15:18:02.416  o.a.activemq.broker.TransportConnector : Connector vm://localhost started
15:18:03.480  o.a.activemq.broker.TransportConnector : Connector vm://localhost stopped
15:18:03.480  o.apache.activemq.broker.BrokerService : Apache ActiveMQ 5.10.1 (localhost, ID:Jordan-801993-L.local-55074-1432703875573-0:7) is shutting down
15:18:03.481  o.apache.activemq.broker.BrokerService : Apache ActiveMQ 5.10.1 (localhost, ID:Jordan-801993-L.local-55074-1432703875573-0:7) uptime 1.069 seconds
15:18:03.481  o.apache.activemq.broker.BrokerService : Apache ActiveMQ 5.10.1 (localhost, ID:Jordan-801993-L.local-55074-1432703875573-0:7) is shutdown
15:18:03.542  o.apache.activemq.broker.BrokerService : Using Persistence Adapter: MemoryPersistenceAdapter
15:18:03.543  o.apache.activemq.broker.BrokerService : Apache ActiveMQ 5.10.1 (localhost, ID:Jordan-801993-L.local-55074-1432703875573-0:8) is starting
15:18:03.543  o.apache.activemq.broker.BrokerService : Apache ActiveMQ 5.10.1 (localhost, ID:Jordan-801993-L.local-55074-1432703875573-0:8) started
15:18:03.543  o.apache.activemq.broker.BrokerService : For help or more information please see: http://activemq.apache.org
15:18:03.544  o.a.a.broker.jmx.ManagementContext     : JMX consoles can connect to service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi
15:18:03.544  o.a.activemq.broker.TransportConnector : Connector vm://localhost started

The project still works fine, it's just annoying. Anyone know why this would be happening?

Jordan
  • 1,875
  • 2
  • 17
  • 24

5 Answers5

10

I cannot explain in-depth why this happens, but it has something to do with the way the ConnectionFactory is auto-configured.

One way to get rid of this constant restarting of the embedded broker is to enable pooling in your application.properties:

spring.activemq.pooled=true

In order to use this you also have to add the following dependency to your pom.xml:

<dependency>
    <groupId>org.apache.activemq</groupId>
    <artifactId>activemq-pool</artifactId>
</dependency> 

I've dug through some documentation and eventually found this

At the bottom of the page it reads:

Using ActiveMQConnectionFactory
...
The broker will be created upon creation of the first connection.
...

Again, this doesn't fully explain what's going on, but I stopped digging once I found that enabling pooling stopped this behaviour from happening.

ci_
  • 8,594
  • 10
  • 39
  • 63
  • You are incredible, I can't thank you enough, this has been bugging me for weeks. Thank you so much <3 <3 <3 cxcxcx – Jordan May 29 '15 at 03:57
  • With this approach there is one Spring Boot gotcha. activemq-pool dependency will add to your classpath Geronimo JTA transaction manager and Spring boot will than use JTA transactions by default. But distributed transactions are well known perf killer. So it is something you may not want in your app. – luboskrnac Jun 07 '15 at 17:56
  • The most recent version of spring boot required the property `spring.activemq.pool.enabled=true` – kenny Sep 01 '17 at 16:30
4

Met the same problem but the accepted answer did not help. Found the thread with explanation

ActiveMQ will only keep an in-memory queue alive if there is something holding onto it.

If the Queue has been setup in spring to not cache the queue then ActiveMQ will keep starting/stopping the connector. A full appserver would effectively cache queue stuff in a pool, thus keeping it alive.

Stick in the bean def for the Spring JMS container (org.springframework.jms.listener.DefaultMessageLi stenerContainer) to fix the problem.

@Bean
public JmsListenerContainerFactory<?> myFactory(ConnectionFactory connectionFactory,
                                                DefaultJmsListenerContainerFactoryConfigurer configurer) {
    DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
    factory.setCacheLevelName("CACHE_CONNECTION"); //<-- the line fixed the problem
    configurer.configure(factory, connectionFactory);
    return factory;
}
Community
  • 1
  • 1
StanislavL
  • 56,971
  • 9
  • 68
  • 98
2

We have spring boot 1.5 services which consume and publish via JMSTemplate and do not have this problem and then we have one which only publishes (so no JmsListener) and fills logs with these messages - plus the related WARN Temporary Store limit is 51200 mb ... resetting to maximum available disk space - writing them on every GET to /healthcheck. You'll want to consider the implications but this behaviour and hence all the related logging can be disabled with the property setting:

management.health.jms.enabled=false

You'll see the jms block disappear from your /healthcheck output as a result - so check whether it is actually reflecting anything required by your service. We had no success with other answers on this thread nor with those we tried from Startup error of embedded ActiveMQ: Temporary Store limit is 51200 mb.

user598656
  • 442
  • 7
  • 10
  • It was related to the health check (`/actuator/health` in my case) for me. Doing as you said stopped the messages. – Will Dec 12 '18 at 14:10
0

What i did, was explicitly create a broker, and tell Spring to use it instead of its implicit one. This way, the broker will be kept alive for sure:

@Configuration
public class MessagingConfig {

    private final static String BROKER_URL = "tcp://localhost:61616";

    @Bean
    public BrokerService brokerService() {
        BrokerService broker = new BrokerService();
        broker.addConnector(BROKER_URL);
        broker.setPersistent(false);
        broker.start();
        return broker;
    }

    @Bean
    public ActiveMQConnectionFactory connectionFactory() {
        ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
        connectionFactory.setBrokerURL(BROKER_URL);
        return connectionFactory;
    }

}
Georg Moser
  • 620
  • 7
  • 14
0

The accepted answer did not suit me, found another solution. Maybe will be helpful:

I you are using Spring Boot application and do not need PooledConnectionFactory, then add this line to your Application class:

@SpringBootApplication(exclude = {ActiveMQAutoConfiguration.class})
public class MyApplication{...}

This will exclude activemq autoconfiguration and you won't see that garbage in the logs.

Alexander Murza
  • 558
  • 5
  • 8