是否有使用SSL连接配置的Springboot ActiveMQ外部代理的完整示例?

时间:2019-01-13 19:33:12

标签: spring-boot ssl activemq

我们有一个带有EJB的activemq侦听器MDB,使用具有代理,SSL证书,凭证配置的activemq-rar.rar连接器通过SSL侦听代理。侦听器在JBOSS EAP 6.4中运行良好。但是,需要将此MDB转换为Spring Boot ActiveMQ侦听器。我可以通过简单的tcp:// localhost:61616看到许多有关Spring Boot ActiveMQ的文章示例。是否完整参考了使用Spring Boot通过SSL通过外部代理生成消息和从外部代理侦听消息的工作示例。

我尝试按照以下说明使用tcp创建生产和消费消息 https://www.devglan.com/spring-boot/spring-boot-jms-activemq-examplehttp://activemq.apache.org/how-do-i-use-ssl.html

spring.activemq.broker-url=ssl://localhost:61616
spring.activemq.user=admin
spring.activemq.password=admin
spring.activemq.keyStore=broker.ks
spring.activemq.keyStorePassword=password

javax.net.ssl.keyStore=client.ks
javax.net.ssl.keyStorePassword=password
javax.net.ssl.trustStore=client.ts

我看到以下异常。需要帮助。

2019-01-14 00:54:33.209  INFO 13964 --- [           main] com.rime.springboot.amc.Application      : Started Application in 5.783 seconds (JVM running for 7.081)
2019-01-14 00:54:38.203  INFO 13964 --- [enerContainer-1] o.s.j.l.DefaultMessageListenerContainer  : JMS message listener invoker needs to establish shared Connection
2019-01-14 00:54:38.244 ERROR 13964 --- [enerContainer-1] o.s.j.l.DefaultMessageListenerContainer  : Could not refresh JMS Connection for destination 'inbound.queue' - retrying using FixedBackOff{interval=5000, currentAttempts=0, maxAttempts=unlimited}. Cause: Could not connect to broker URL: ssl://localhost:61616. Reason: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
2019-01-14 00:54:43.341 ERROR 13964 --- [enerContainer-1] o.s.j.l.DefaultMessageListenerContainer  : Could not refresh JMS Connection for destination 'inbound.queue' - retrying using FixedBackOff{interval=5000, currentAttempts=1, maxAttempts=unlimited}. Cause: Could not connect to broker URL: ssl://localhost:61616. Reason: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?

1 个答案:

答案 0 :(得分:1)

看来,当前支持通过属性进行自动配置。参见:https://github.com/spring-projects/spring-boot/issues/17365https://github.com/spring-projects/spring-boot/issues/17589

同时,可以使用您自己的ActiveMQSslConnectionFactory bean覆盖默认连接,提供所需的SSL配置属性:

@Configuration
public class ActiveMQConfiguration {

    @Bean
    public ActiveMQSslConnectionFactory activeMQSslConnectionFactory(
            @Value("${spring.activemq.broker-url}") String brokerUrl,
            @Value("${spring.activemq.ssl.trustStorePath}") String trustStorePath,
            @Value("${spring.activemq.ssl.trustStorePass}") String trustStorePass,
            @Value("${spring.activemq.ssl.keyStorePath}") String keyStorePath,
            @Value("${spring.activemq.ssl.keyStorePass}") String keyStorePass) throws Exception {
        ActiveMQSslConnectionFactory factory = new ActiveMQSslConnectionFactory(brokerUrl);
        factory.setTrustStore(trustStorePath);
        factory.setTrustStorePassword(trustStorePass);
        factory.setKeyStore(keyStorePath);
        factory.setKeyStorePassword(keyStorePass);
        return factory;
    }
}

spring.activemq.ssl.*属性并非基于任何现有或记录的属性,因此您不需要专门使用这些属性。