通过Spring Boot连接到Tibco主题时,身份验证失败

我试图在我的Spring Boot应用程序中收听通过Tibco主题发送的消息。我的配置看起来像这样-

@Configuration
@EnableJms
public class TibcoConfig {

    @Bean
    public ConnectionFactory connectionFactory() {
        TopicConnectionFactory factory = new TibjmsTopicConnectionFactory("TIBCO_BROKER_URL");
        return factory;
    }

    @Bean
    public DefaultJmsListenerContainerFactory jmsListenerContainerFactory() {
        DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
        factory.setConnectionFactory(connectionFactory());
        factory.setClientId("client1");
        factory.setPubSubDomain(true);
        factory.setSessionAcknowledgeMode(Session.AUTO_ACKNOWLEDGE);
        return factory;
    }

    @Bean
    public UserCredentialsConnectionFactoryAdapter authenticationConnectionFactory() {
        UserCredentialsConnectionFactoryAdapter userCredentialsConnectionFactoryAdapter = new UserCredentialsConnectionFactoryAdapter();
        userCredentialsConnectionFactoryAdapter.setTargetconnectionFactory(connectionFactory());
        userCredentialsConnectionFactoryAdapter.setusername("username");
        userCredentialsConnectionFactoryAdapter.setPassword("PASSWORD");
        return userCredentialsConnectionFactoryAdapter;
    }
}

我的听众看起来像这样-

@Component
public class TibcoRequestListener {

    @JmsListener(destination = "TIBCO_TOPIC_NAME",containerFactory = "jmsListenerContainerFactory")
    public void receiveMessage(Message message) {
        try {
            TextMessage txtMsg = (TextMessage) message;
            System.out.println("Received response: " + txtMsg.getText());
            System.out.println("Message type: " + message.getJMSType());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

错误日志-

2020-07-08 18:28:37.711  WARN 3552 --- [)-10.110.74.130] o.s.boot.actuate.jms.JmsHealthIndicator  : JMS health check failed

javax.jms.JMSSecurityException: authentication failed
    at com.tibco.tibjms.Tibjmsx.buildException(Tibjmsx.java:575) ~[tibjms-5.1.0.jar:5.1.0]
    at com.tibco.tibjms.TibjmsConnection._create(TibjmsConnection.java:1330) ~[tibjms-5.1.0.jar:5.1.0]
    at com.tibco.tibjms.TibjmsConnection.<init>(TibjmsConnection.java:4115) ~[tibjms-5.1.0.jar:5.1.0]
    at com.tibco.tibjms.TibjmsTopicConnection.<init>(TibjmsTopicConnection.java:36) ~[tibjms-5.1.0.jar:5.1.0]
    at com.tibco.tibjms.TibjmsxcfImpl._createImpl(TibjmsxcfImpl.java:191) ~[tibjms-5.1.0.jar:5.1.0]
    at com.tibco.tibjms.TibjmsxcfImpl._createConnection(TibjmsxcfImpl.java:253) ~[tibjms-5.1.0.jar:5.1.0]
    at com.tibco.tibjms.TibjmsConnectionFactory.createConnection(TibjmsConnectionFactory.java:36) ~[tibjms-5.1.0.jar:5.1.0]
    at org.springframework.boot.actuate.jms.JmsHealthIndicator.doHealthCheck(JmsHealthIndicator.java:52) ~[spring-boot-actuator-2.2.6.RELEASE.jar:2.2.6.RELEASE]
    at org.springframework.boot.actuate.health.AbstractHealthIndicator.health(AbstractHealthIndicator.java:82) ~[spring-boot-actuator-2.2.6.RELEASE.jar:2.2.6.RELEASE]
    at org.springframework.boot.actuate.health.HealthIndicator.getHealth(HealthIndicator.java:37) ~[spring-boot-actuator-2.2.6.RELEASE.jar:2.2.6.RELEASE]
    at org.springframework.boot.actuate.health.HealthEndpoint.getHealth(HealthEndpoint.java:81) ~[spring-boot-actuator-2.2.6.RELEASE.jar:2.2.6.RELEASE]
    at org.springframework.boot.actuate.health.HealthEndpoint.getHealth(HealthEndpoint.java:38) ~[spring-boot-actuator-2.2.6.RELEASE.jar:2.2.6.RELEASE]
    at org.springframework.boot.actuate.health.HealthEndpointSupport.getcontribution(HealthEndpointSupport.java:108) ~[spring-boot-actuator-2.2.6.RELEASE.jar:2.2.6.RELEASE]
    at org.springframework.boot.actuate.health.HealthEndpointSupport.getaggregateHealth(HealthEndpointSupport.java:119) ~[spring-boot-actuator-2.2.6.RELEASE.jar:2.2.6.RELEASE]
    at org.springframework.boot.actuate.health.HealthEndpointSupport.getcontribution(HealthEndpointSupport.java:105) ~[spring-boot-actuator-2.2.6.RELEASE.jar:2.2.6.RELEASE]
    at org.springframework.boot.actuate.health.HealthEndpointSupport.getaggregateHealth(HealthEndpointSupport.java:119) ~[spring-boot-actuator-2.2.6.RELEASE.jar:2.2.6.RELEASE]
    at org.springframework.boot.actuate.health.HealthEndpointSupport.getcontribution(HealthEndpointSupport.java:105) ~[spring-boot-actuator-2.2.6.RELEASE.jar:2.2.6.RELEASE]
    at org.springframework.boot.actuate.health.HealthEndpointSupport.getHealth(HealthEndpointSupport.java:83) ~[spring-boot-actuator-2.2.6.RELEASE.jar:2.2.6.RELEASE]
    at org.springframework.boot.actuate.health.HealthEndpointSupport.getHealth(HealthEndpointSupport.java:70) ~[spring-boot-actuator-2.2.6.RELEASE.jar:2.2.6.RELEASE]
    at org.springframework.boot.actuate.health.HealthEndpoint.health(HealthEndpoint.java:75) ~[spring-boot-actuator-2.2.6.RELEASE.jar:2.2.6.RELEASE]
    at org.springframework.boot.actuate.health.HealthEndpoint.health(HealthEndpoint.java:65) ~[spring-boot-actuator-2.2.6.RELEASE.jar:2.2.6.RELEASE]
    at java.base/jdk.internal.reflect.NativeMethodaccessorImpl.invoke0(Native Method) ~[na:na]
    at java.base/jdk.internal.reflect.NativeMethodaccessorImpl.invoke(NativeMethodaccessorImpl.java:62) ~[na:na]
    at java.base/jdk.internal.reflect.DelegatingMethodaccessorImpl.invoke(DelegatingMethodaccessorImpl.java:43) ~[na:na]
    at java.base/java.lang.reflect.Method.invoke(Method.java:564) ~[na:na]
    at org.springframework.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:282) ~[spring-core-5.2.5.RELEASE.jar:5.2.5.RELEASE]
    at org.springframework.boot.actuate.endpoint.invoke.reflect.ReflectiveOperationInvoker.invoke(ReflectiveOperationInvoker.java:77) ~[spring-boot-actuator-2.2.6.RELEASE.jar:2.2.6.RELEASE]
    at org.springframework.boot.actuate.endpoint.annotation.AbstractDiscoveredOperation.invoke(AbstractDiscoveredOperation.java:60) ~[spring-boot-actuator-2.2.6.RELEASE.jar:2.2.6.RELEASE]
    at org.springframework.boot.actuate.endpoint.jmx.EndpointMBean.invoke(EndpointMBean.java:121) ~[spring-boot-actuator-2.2.6.RELEASE.jar:2.2.6.RELEASE]
    at org.springframework.boot.actuate.endpoint.jmx.EndpointMBean.invoke(EndpointMBean.java:96) ~[spring-boot-actuator-2.2.6.RELEASE.jar:2.2.6.RELEASE]
    at java.management/com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:809) ~[na:na]
    at java.management/com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) ~[na:na]
    at java.management.rmi/javax.management.remote.rmi.rmiconnectionImpl.doOperation(rmiconnectionImpl.java:1466) ~[na:na]
    at java.management.rmi/javax.management.remote.rmi.rmiconnectionImpl$PrivilegedOperation.run(rmiconnectionImpl.java:1307) ~[na:na]
    at java.management.rmi/javax.management.remote.rmi.rmiconnectionImpl.doPrivilegedOperation(rmiconnectionImpl.java:1399) ~[na:na]
    at java.management.rmi/javax.management.remote.rmi.rmiconnectionImpl.invoke(rmiconnectionImpl.java:827) ~[na:na]
    at java.base/jdk.internal.reflect.GeneratedMethodaccessor147.invoke(Unknown Source) ~[na:na]
    at java.base/jdk.internal.reflect.DelegatingMethodaccessorImpl.invoke(DelegatingMethodaccessorImpl.java:43) ~[na:na]
    at java.base/java.lang.reflect.Method.invoke(Method.java:564) ~[na:na]
    at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:359) ~[na:na]
    at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200) ~[na:na]
    at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197) ~[na:na]
    at java.base/java.security.accessController.doPrivileged(accessController.java:691) ~[na:na]
    at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196) ~[na:na]
    at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:587) ~[na:na]
    at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:828) ~[na:na]
    at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:705) ~[na:na]
    at java.base/java.security.accessController.doPrivileged(accessController.java:391) ~[na:na]
    at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:704) ~[na:na]
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130) ~[na:na]
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630) ~[na:na]
    at java.base/java.lang.Thread.run(Thread.java:832) ~[na:na]

2020-07-08 18:28:39.955 ERROR 3552 --- [enerContainer-1] o.s.j.l.DefaultMessageListenerContainer  : Could not refresh JMS Connection for destination 'TIBCO_TOPIC_NAME' - retrying using FixedBackOff{interval=5000,currentAttempts=0,maxAttempts=unlimited}. Cause: authentication failed
2020-07-08 18:28:45.033 ERROR 3552 --- [enerContainer-1] o.s.j.l.DefaultMessageListenerContainer  : Could not refresh JMS Connection for destination 'TIBCO_TOPIC_NAME' - retrying using FixedBackOff{interval=5000,maxAttempts=unlimited}. Cause: authentication failed
...
...
...

即使用户名和密码是通过UserCredentialsConnectionFactoryAdapter提供的,Spring Boot应用程序为何仍无法验证与tibco主题的连接?我还需要配置其他内容吗?

我能够连接到本主题,并在不使用Spring Boot的不同设置中使用相同的凭据成功接收消息。而且我需要使用现有的Spring引导应用程序来完成这项工作。

iCMS 回答:通过Spring Boot连接到Tibco主题时,身份验证失败

能够找出解决方案,以防其他任何人被卡住。在春季启动中,不需要TopicConnectionFactory对象来指定我们需要连接到Tibco Topic(而不是Queue),这在独立应用程序中是必需的。当PubSubDomain属性设置为true时,它将自动完成。因此,请改用具有设置凭据的方法的TibjmsConnectionFactory。完全不需要UserCredentialsConnectionFactoryAdapter。

我将配置代码更改为以下代码,它开始工作!

@Configuration
@EnableJms
public class TibcoConfig {

    @Bean
    public ConnectionFactory connectionFactory() {
        TibjmsConnectionFactory factory = new TibjmsConnectionFactory("TIBCO_BROKER_URL");
        factory.setUserName("USERNAME");
        factory.setUserPassword("PASSWORD");
        return factory;
    }

    @Bean
    public DefaultJmsListenerContainerFactory jmsListenerContainerFactory() {
        DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
        factory.setConnectionFactory(connectionFactory());
        factory.setClientId("client1");
        factory.setPubSubDomain(true);
        factory.setSessionAcknowledgeMode(Session.AUTO_ACKNOWLEDGE);
        return factory;
    }
}
本文链接:https://www.f2er.com/1972039.html

大家都在问