gpt4 book ai didi

java - 如何禁用ActiveMQ中的InactivityMonitor日志?

转载 作者:行者123 更新时间:2023-11-30 02:25:28 27 4
gpt4 key购买 nike

我已经在我的应用程序中实现了 ActiveMQ 消息代理,但是每当我在控制台日志中连接到 ActiveMQ 服务器时,我总是会看到以下消息:

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]

看起来它似乎一直在轮询监听器队列。我希望我的监听器处于 Activity 状态,以便每当消息到达队列时,应用程序就可以处理它。同时,我不希望此消息堆积在我的日志文件中。

我的消息配置:

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

}

解决方案:我通过以下链接禁用 InactivityMonitor 找到了问题的解决方案 ActiveMQ InactivityMonitor 。我测试了它,连接仍然存在,并且它不会继续轮询队列。但我想知道禁用 InactivityMonitor 是否会带来任何影响?对于这个问题有没有更好的解决办法。

activemq.broker.url=failover:tcp://localhost:61616?wireFormat.maxInactivityDuration=0

最佳答案

修复方法很简单,将日志记录设置更改为不在调试级别写入或过滤该记录器使其不处于调试级别。这些日志让您随时了解客户端已成功 ping 远程代理以确保连接处于 Activity 状态的事实。如果禁用监视,那么您可能会错过连接断开事件,例如半关闭套接字等。

在生产中,您确实不想关闭连接检查功能,因为这会导致您的代码错过它无法接收任何内容的事实

配置修改示例:

<logger name="org.apache.activemq.transport" level="WARN"/>

关于java - 如何禁用ActiveMQ中的InactivityMonitor日志?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45740655/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com