Is there a complete example for Springboot ActiveMQ external broker with SSL Connection configuration?

Viewed 3219

We have an activemq listener MDB with EJB, listening to a broker over SSL using activemq-rar.rar connector that has the broker, SSL cert, credential configurations. The listener is running well in JBOSS EAP 6.4. However, the need is to convert this MDB into Spring Boot ActiveMQ listener. I could see many articles examples about Spring Boot ActiveMQ with simple tcp://localhost:61616. Is there a complete reference to working example of producing message to and listening message from external broker over SSL using Spring Boot.

I have tried to create produce and consume messages using tcp per the instructions at https://www.devglan.com/spring-boot/spring-boot-jms-activemq-example and http://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

I am seeing below exception. Need help.

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 Answers

It appears that auto-configuration via properties is not currently supported. See: https://github.com/spring-projects/spring-boot/issues/17365 and https://github.com/spring-projects/spring-boot/issues/17589.

In the meantime, it is possible to override the default connection with your own ActiveMQSslConnectionFactory bean, providing the SSL configuration properties you need:

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

The spring.activemq.ssl.* properties aren't based on any existing or documented properties, so you don't need to use those specifically.

Related