From 6b379e6fb4a70cd06ceb75aee090b34f3139990e Mon Sep 17 00:00:00 2001 From: Zoltan Mezei Date: Tue, 7 Nov 2023 15:08:52 +0100 Subject: [PATCH] Add username/password handling for the message broker factory --- .../MessageConsumerJMSBrokerConfiguration.java | 14 ++++++++++++++ src/main/resources/application.properties | 2 ++ 2 files changed, 16 insertions(+) diff --git a/src/main/java/org/test/consumer/config/MessageConsumerJMSBrokerConfiguration.java b/src/main/java/org/test/consumer/config/MessageConsumerJMSBrokerConfiguration.java index c636807..bcf24cb 100644 --- a/src/main/java/org/test/consumer/config/MessageConsumerJMSBrokerConfiguration.java +++ b/src/main/java/org/test/consumer/config/MessageConsumerJMSBrokerConfiguration.java @@ -1,9 +1,11 @@ package org.test.consumer.config; + import org.apache.activemq.ActiveMQConnectionFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.util.StringUtils; @Configuration public class MessageConsumerJMSBrokerConfiguration { @@ -11,10 +13,22 @@ public class MessageConsumerJMSBrokerConfiguration { @Value("${brokerurl}") private String brokerUrl; + @Value("${brokerusername") + private String brokerUserName; + + @Value("${brokerpassword") + private String brokerPassword; + @Bean public ActiveMQConnectionFactory connectionFactory() { ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(); connectionFactory.setBrokerURL(brokerUrl); + if (StringUtils.hasText(brokerUserName)) { + connectionFactory.setUserName(brokerUserName); + } + if (StringUtils.hasText(brokerPassword)) { + connectionFactory.setPassword(brokerPassword); + } connectionFactory.setTrustAllPackages(true); return connectionFactory; } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 441ef5d..9a54ccb 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,5 +1,7 @@ queuename=${EVENT_QUEUE_NAME:JMS-event-queue} brokerurl=${JMS_BROKER_URL:tcp://127.0.0.1:61616} +brokerusername=${JMS_BROKER_USERNAME:} +brokerpassword=${JMS_BROKER_PASSWORD:} spring.datasource.url=jdbc:h2:mem:testdb spring.datasource.username=sa