I have implemented ActiveMQ message broker in my application but whenever I'm connected to ActiveMQ server in my console logs I'm always seeing the below messages:
10:28:05.282 [ActiveMQ InactivityMonitor WriteCheckTimer] DEBUG o.a.a.t.AbstractInactivityMonitor - WriteChecker: 10000ms elapsed since last write check.
10:28:05.282 [ActiveMQ InactivityMonitor Worker] DEBUG o.a.a.t.AbstractInactivityMonitor - Running WriteCheck[tcp://10.211.127.203:61616]
Looks it keep on polling the listener queue it seems. I want my listener to be active so that whenever the message comes to the queue, the application can process it. At the same time, i do not want this message to pile up my log file.
My message configuration:
@Configuration
@EnableJms
@ImportResource("classpath*:beans.xml")
public class MessagingConfiguration {
@Autowired
MongoCredentialEncryptor encryptor;
@Value("${activemq.broker.url}")
private String BROKER_URL = "tcp://localhost:61616";
@Value("${activemq.request.queue}")
private String REQUEST_QUEUE = "test.request";
@Value("${activemq.response.queue}")
private String RESPONSE_QUEUE = "test.response";
@Value("${activemq.borker.username}")
private String BROKER_USERNAME = "admin";
@Value("${activemq.borker.password}")
private String BROKER_PASSWORD = "admin";
@Autowired
ListenerClass messageListener;
@Autowired
JmsExceptionListener jmsExceptionListener;
@Bean
public ActiveMQConnectionFactory connectionFactory() {
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
connectionFactory.setBrokerURL(BROKER_URL);
connectionFactory.setUserName(BROKER_USERNAME);
//connectionFactory.setPassword(BROKER_PASSWORD);
connectionFactory.setPassword(encryptor.decrypt(BROKER_PASSWORD));
connectionFactory.setTrustAllPackages(true);
connectionFactory.setRedeliveryPolicy(redeliveryPolicy());
return connectionFactory;
}
@Bean
public RedeliveryPolicy redeliveryPolicy() {
RedeliveryPolicy redeliveryPolicy = new RedeliveryPolicy();
redeliveryPolicy.setBackOffMultiplier(3); // Wait 5 seconds first re-delivery, then 15, 45 seconds
redeliveryPolicy.setInitialRedeliveryDelay(5000);
redeliveryPolicy.setMaximumRedeliveries(3);
redeliveryPolicy.setUseExponentialBackOff(true);
return redeliveryPolicy;
}
@Bean
public ConnectionFactory cachingConnectionFactory() {
CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
connectionFactory.setTargetConnectionFactory(connectionFactory());
connectionFactory.setExceptionListener(jmsExceptionListener);
connectionFactory.setSessionCacheSize(100);
connectionFactory.setCacheConsumers(false);
connectionFactory.setCacheProducers(false);
return connectionFactory;
}
@Bean
public JmsTemplate jmsTemplate() {
JmsTemplate template = new JmsTemplate();
template.setConnectionFactory(connectionFactory());
template.setDefaultDestinationName(REQUEST_QUEUE);
template.setSessionAcknowledgeModeName("CLIENT_ACKNOWLEDGE");
template.setMessageConverter(converter());
return template;
}
@Bean
public DefaultMessageListenerContainer jmsListenerContainer() {
DefaultMessageListenerContainer factory = new DefaultMessageListenerContainer();
factory.setConnectionFactory(connectionFactory());
factory.setConcurrency("1-1");
factory.setDestinationName(RESPONSE_QUEUE);
factory.setMessageListener(messageListener);
factory.setExceptionListener(jmsExceptionListener);
return factory;
}
@Bean
MessageConverter converter() {
MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
converter.setTargetType(MessageType.TEXT);
converter.setTypeIdPropertyName("_type");
return converter;
}
}
Solution: I found a solution to my problem by disabling the InactivityMonitor by following this link ActiveMQ InactivityMonitor. I tested it the connection is still alive and its not keep on polling the queue. But i would like to know is there any downfall by disabling InactivityMonitor? Is there any better solution for this problem.
activemq.broker.url=failover:tcp://localhost:61616?wireFormat.maxInactivityDuration=0
The fix is simple, change your logging settings to not write at debug level or filter that one logger to not be at debug level. The logs are keeping you updated on the fact that the client is successfully pinging the remote broker to ensure the connection is alive. If you disable the monitoring then you can miss connection drop events are things like half closed sockets etc.
In production you really don't want to be turning off connection checking features that cause your code to miss the fact that it is not going to be able to receive anything
Example configuration modification:
<logger name="org.apache.activemq.transport" level="WARN"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With