Spring Download the same broker messages that are repeated in the console

I'm currently working on a Spring boot project, this text continues to print to the console every second thirty seconds before it stops.

15:18:02.416 oaactivemq.broker.TransportConnector : Connector vm://localhost started 15:18:03.480 oaactivemq.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 oaabroker.jmx.ManagementContext : JMX consoles can connect to service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi 15:18:03.544 oaactivemq.broker.TransportConnector : Connector vm://localhost started 

The project is still working fine, it's just annoying. Does anyone know why this is happening?

+8
spring spring-boot activemq
source share
4 answers

I can’t explain in detail why this is happening, but it has something to do with how ConnectionFactory automatically configured.

One way to get rid of this constant restart of the built-in broker is to include the union in application.properties :

 spring.activemq.pooled=true 

To use this, you also need to add the following dependency to your pom.xml :

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

I dug some documentation and eventually found this

At the bottom of the page, it reads:

Using ActiveMQConnectionFactory
...
A broker will be created when the first connection is created.
...

Again, this does not fully explain what is happening, but I stopped digging as soon as I found that turning on the pool stopped this behavior.

+8
source share

I met the same problem, but the accepted answer did not help. Explained stream

ActiveMQ will only maintain a queue in memory if it has something on it.

If Queue is configured in spring so as not to cache the queue, ActiveMQ will continue to start / stop the connector. A full application server effectively caches the contents of the queue in the pool, thereby preserving it.

Stick in bean def for 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; } 
+1
source share

What I did explicitly created a broker and told Spring to use it instead of its implicit. Thus, 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; } } 
0
source share

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

I am using a Spring Boot application and not > PooledConnectionFactory , then add this line to my Application class:

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

This eliminates the activemq auto-configuration and you will not see this garbage in the logs.

0
source share

All Articles