Jordan
Jordan

Reputation: 1965

Spring Boot same broker messages repeated to console

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?

Upvotes: 11

Views: 4385

Answers (5)

user598656
user598656

Reputation: 462

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.

Upvotes: 2

Alexander Murza
Alexander Murza

Reputation: 568

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.

Upvotes: 0

Georg Moser
Georg Moser

Reputation: 706

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

}

Upvotes: 0

StanislavL
StanislavL

Reputation: 57421

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

Upvotes: 4

ci_
ci_

Reputation: 8774

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.

Upvotes: 10

Related Questions