即使在属性文件中指定订阅者客户端 ID 后,我仍看到以下错误。我正在使用 Spring Boot 3.3.4
2024-10-28T15:47:30.173-04:00 WARN 14156 --- [(2)-10.1.81.174] o.s.boot.actuate.jms.JmsHealthIndicator : JMS health check failed
com.ibm.msg.client.jakarta.jms.DetailedInvalidClientIDException: JMSCC0111: IBM MQ classes for JMS attempted to set a pre-existing client ID on a Connection or JMSContext.
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:na]
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) ~[na:na]
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480) ~[na:na]
at com.ibm.msg.client.commonservices.j2se.NLSServices.createException(NLSServices.java:334) ~[com.ibm.mq.jakarta.client-9.3.3.0.jar:9.3.3.0 - p933-L230531]
at com.ibm.msg.client.commonservices.nls.NLSServices.createException(NLSServices.java:226) ~[com.ibm.mq.jakarta.client-9.3.3.0.jar:9.3.3.0 - p933-L230531]
at com.ibm.msg.client.jakarta.jms.internal.JmsErrorUtils.createException(JmsErrorUtils.java:126) ~[com.ibm.mq.jakarta.client-9.3.3.0.jar:9.3.3.0 - p933-L230531]
下面是我的 application.properties 文件的样子
ibm.mq.queue-manager=${MQ_QUEUE_MANAGER}
ibm.mq.topicName=${MQ_TOPIC_NAME}
ibm.mq.channel=${MQ_CHANNEL}
ibm.mq.connName=${MQ_HOSTNAME}
ibm.mq.user=${MQ_USERNAME}
ibm.mq.password=${MQ_PASSWORD}
ibm.mq.application-name=${MQ_SUBSCRIBER_NAME}
ibm.mq.client-id=${MQ_SUBSCRIBER_CLIENT_ID}
连接详细信息准确,客户端 ID 也已传递。
下面是我的MQ连接配置文件:
import com.ibm.mq.jakarta.jms.MQConnectionFactory;
import com.ibm.mq.spring.boot.MQConfigurationProperties;
import com.ibm.mq.spring.boot.MQConnectionFactoryCustomizer;
import com.ibm.mq.spring.boot.MQConnectionFactoryFactory;
import jakarta.jms.ConnectionFactory;
import java.util.List;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.jms.DefaultJmsListenerContainerFactoryConfigurer;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jms.annotation.EnableJms;
import org.springframework.jms.config.DefaultJmsListenerContainerFactory;
import org.springframework.jms.config.JmsListenerContainerFactory;
@Configuration
@EnableJms
public class MQConnectionConfiguration {
@Bean
@ConfigurationProperties("ibm.mq")
public MQConfigurationProperties ibmProductConfigProperties() {
return new MQConfigurationProperties();
}
@Bean
public MQConnectionFactory connectionFactory(final MQConfigurationProperties properties,
ObjectProvider<List<MQConnectionFactoryCustomizer>> factoryCustomizers) {
return new MQConnectionFactoryFactory(properties, factoryCustomizers.getIfAvailable()).createConnectionFactory(MQConnectionFactory.class);
}
@Bean
public JmsListenerContainerFactory<?> jmsListenerContainerFactory(@Qualifier("connectionFactory") ConnectionFactory connectionFactory,
DefaultJmsListenerContainerFactoryConfigurer configurer) {
final DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
factory.setSubscriptionDurable(true);
configurer.configure(factory, connectionFactory);
return factory;
}
}
下面我也添加了 gradle 依赖项
implementation("org.springframework.integration:spring-integration-jms:4.3.2.RELEASE")
implementation("javax.jms:javax.jms-api:2.0.1")
implementation 'com.ibm.mq:mq-jms-spring-boot-starter:3.1.2'
如何消除上述错误?
这是错误的相关部分:
JMSCC0111: IBM MQ classes for JMS attempted to set a pre-existing client ID on a Connection or JMSContext.
此消息告诉您,您正在 JMS
Connection
(或 JMSContext
)上设置一个已在使用中的客户端 ID。
JMS 规范要求每个
Connection
/JMSContext
的客户端 ID 必须是唯一的。因此,您需要更改 ibm.mq.client-id
值,使其在连接到 JMS 代理的所有客户端中都是唯一的。