每当我调用/actuator/health
时,我的IBM MQ组件中都有一个实例不应该被检查,在本例中是mqQueueConnectionFactory
(因为它是一种用于生成MQQueueConnectionFactory
的方法,并且没有连接到队列所需的身份验证(。名称确实与配置的bean匹配,因此例如mqQueueConnectionFactory
与mqQueueConnectionFactory
bean匹配。
{
"status": "DOWN",
"details": {
"jms": {
"status": "DOWN",
"details": {
"connectionFactory": {
"status": "UP",
"details": {
"provider": "IBM MQ JMS Provider"
}
},
"queueConnectionFactory": {
"status": "UP",
"details": {
"provider": "IBM MQ JMS Provider"
}
},
"mqQueueConnectionFactory": {
"status": "DOWN",
"details": {
"error": "com.ibm.msg.client.jms.DetailedJMSSecurityException: JMSWMQ2013: The security authentication was not valid that was supplied for QueueManager 'GIMLI_A1' with connection mode 'Client' and host name 'gimli-a1.it.company.net(1417)'."
}
},
"userCredentialsConnectionFactoryAdapter": {
"status": "UP",
"details": {
"provider": "IBM MQ JMS Provider"
}
},
"cachingConnectionFactory": {
"status": "UP",
"details": {
"provider": "IBM MQ JMS Provider"
}
}
}
},
"db": {
"status": "UP",
"details": {
"tnvet": {
"status": "UP",
"details": {
"database": "DB2",
"hello": 1
}
},
"nk": {
"status": "UP",
"details": {
"database": "DB2",
"hello": 1
}
}
}
}
}
}
有没有办法定义某些细节不应该包括在健康检查中?不幸的是,删除bean的返工不是一种选择。
附加信息:
Java版本:8Spring Boot版本:2.1.9.RELASE弹簧套执行器:2.1.9.释放IBM MQ JMS Spring Boot Starter:0.0.3
配置文件:
@Configuration
public class AppConfiguration {
@Value("${ibm.mq.hostName}")
private String mqHostName;
@Value("${ibm.mq.port}")
private int mqPort;
@Value("${ibm.mq.queueManager}")
private String mqQueueManager;
@Value("${ibm.mq.channel}")
private String mqChannel;
@Value("${ibm.mq.user}")
private String mqUser;
@Value("${ibm.mq.password}")
private String mqPassword;
@Bean
public FilterRegistrationBean<CorsFilter> corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration config = new CorsConfiguration();
config.setAllowCredentials(true);
config.addAllowedOrigin("*");
config.addAllowedHeader("*");
config.addAllowedMethod("*");
source.registerCorsConfiguration("/**", config);
FilterRegistrationBean<CorsFilter> bean = new FilterRegistrationBean<>(new CorsFilter(source));
bean.setOrder(Ordered.HIGHEST_PRECEDENCE);
return bean;
}
@Bean
public ConnectionFactory connectionFactory() throws JMSException {
return userCredentialsConnectionFactoryAdapter(mqQueueConnectionFactory());
}
@Bean
public QueueConnectionFactory queueConnectionFactory() throws JMSException {
return userCredentialsConnectionFactoryAdapter(mqQueueConnectionFactory());
}
@Bean
public MQQueueConnectionFactory mqQueueConnectionFactory() throws JMSException {
MQQueueConnectionFactory cf = new MQQueueConnectionFactory();
// Get these settings from the application properties
cf.setHostName(mqHostName);
cf.setPort(mqPort);
cf.setQueueManager(mqQueueManager);
cf.setChannel(mqChannel);
cf.setTransportType(CommonConstants.WMQ_CM_CLIENT);
return cf;
}
@Bean(name = "jmsPlatformTransactionManager")
public PlatformTransactionManager platformTransactionManager(CachingConnectionFactory cachingConnectionFactory) {
cachingConnectionFactory.setCacheConsumers(true);
cachingConnectionFactory.setSessionCacheSize(5);
cachingConnectionFactory.setReconnectOnException(true);
return new JmsTransactionManager(cachingConnectionFactory);
}
@Bean
public DefaultJmsListenerContainerFactory defaultJmsListenerContainerFactory(//
PlatformTransactionManager jmsPlatformTransactionManager, //
CachingConnectionFactory cachingConnectionFactory) {
DefaultJmsListenerContainerFactory defaultJmsListenerContainerFactory = new DefaultJmsListenerContainerFactory();
defaultJmsListenerContainerFactory.setConnectionFactory(cachingConnectionFactory);
defaultJmsListenerContainerFactory.setTransactionManager(jmsPlatformTransactionManager);
defaultJmsListenerContainerFactory.setConcurrency("1-1");
defaultJmsListenerContainerFactory.setSessionAcknowledgeMode(Session.CLIENT_ACKNOWLEDGE);
defaultJmsListenerContainerFactory.setSessionTransacted(true);
return defaultJmsListenerContainerFactory;
}
@Bean
public UserCredentialsConnectionFactoryAdapter userCredentialsConnectionFactoryAdapter(MQQueueConnectionFactory mqQueueConnectionFactory) {
UserCredentialsConnectionFactoryAdapter userCredentialsConnectionFactoryAdapter = new UserCredentialsConnectionFactoryAdapter();
userCredentialsConnectionFactoryAdapter.setUsername(mqUser);
userCredentialsConnectionFactoryAdapter.setPassword(mqPassword);
userCredentialsConnectionFactoryAdapter.setTargetConnectionFactory(mqQueueConnectionFactory);
return userCredentialsConnectionFactoryAdapter;
}
@Bean
public JmsListenerContainerFactory<DefaultMessageListenerContainer> myFactory(CachingConnectionFactory cachingConnectionFactory,
DefaultJmsListenerContainerFactoryConfigurer configurer) {
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
factory.setSessionTransacted(false);
factory.setConcurrency("1-1");
configurer.configure(factory, cachingConnectionFactory);
return factory;
}
@Bean
public CachingConnectionFactory cachingConnectionFactory(UserCredentialsConnectionFactoryAdapter userCredentialsConnectionFactoryAdapter) {
CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory();
cachingConnectionFactory.setTargetConnectionFactory(userCredentialsConnectionFactoryAdapter);
cachingConnectionFactory.setCacheConsumers(true);
cachingConnectionFactory.setSessionCacheSize(5);
cachingConnectionFactory.setCacheProducers(true);
cachingConnectionFactory.setReconnectOnException(true);
return cachingConnectionFactory;
}
@Bean
public JmsOperations jmsOperations(CachingConnectionFactory cachingConnectionFactory) {
JmsTemplate jmsTemplate = new JmsTemplate(cachingConnectionFactory);
jmsTemplate.setReceiveTimeout(10);
return jmsTemplate;
}
@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}
}
如果您想从/executor/health中删除任何自定义健康检查,可以使用@ConditionalOnEnabledHealthIndicator注释。
@Component
@ConditionalOnEnabledHealthIndicator("mqFactory")
public class MqHealthIndicator implements HealthIndicator {
@Autowired
private MQQueueConnectionFactory mqQueueConnectionFactory;
@Override
public Health health() {
Health.Builder status;
//your logic to check if mq is up
if (mqQueueConnectionFactory is up) {
status = Health.up();
} else {
status = Health.down();
}
return status.build();
}
}
以及在您的房产中。文件
management.health.mqFactory.enabled=false