From 88c18f70cf24ffb66be81c0872e98d382eb7d426 Mon Sep 17 00:00:00 2001 From: hong seokho Date: Tue, 30 Jul 2024 12:28:28 +0900 Subject: [PATCH 1/2] =?UTF-8?q?fix=20:=20rabbitmq=20ssl=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/rabbitmq/RabbitmqConfig.java | 21 +++++++++++++- .../config/rabbitmq/RabbitmqProperties.java | 28 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 backend/core/src/main/java/site/timecapsulearchive/core/global/config/rabbitmq/RabbitmqProperties.java diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/global/config/rabbitmq/RabbitmqConfig.java b/backend/core/src/main/java/site/timecapsulearchive/core/global/config/rabbitmq/RabbitmqConfig.java index 599915c2..9933cf40 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/global/config/rabbitmq/RabbitmqConfig.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/global/config/rabbitmq/RabbitmqConfig.java @@ -1,5 +1,7 @@ package site.timecapsulearchive.core.global.config.rabbitmq; +import java.security.KeyManagementException; +import java.security.NoSuchAlgorithmException; import lombok.RequiredArgsConstructor; import org.springframework.amqp.core.Binding; import org.springframework.amqp.core.BindingBuilder; @@ -11,6 +13,7 @@ import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import site.timecapsulearchive.core.global.error.exception.InternalServerException; @Configuration @RequiredArgsConstructor @@ -19,6 +22,8 @@ public class RabbitmqConfig { private static final int MAX_RETRY_COUNT = 3; private static final String RETRY_HEADER = "x-retry-count"; + private final RabbitmqProperties rabbitmqProperties; + @Bean public Queue capsuleSkinQueue() { return new Queue(RabbitmqComponentConstants.CAPSULE_SKIN_QUEUE.getSuccessComponent(), true); @@ -153,7 +158,21 @@ public RabbitTemplate publisherConfirmsRabbitTemplate() { public CachingConnectionFactory publisherConfirmsConnectionFactory() { CachingConnectionFactory connectionFactory = new CachingConnectionFactory(); - connectionFactory.afterPropertiesSet(); + connectionFactory.setHost(rabbitmqProperties.host()); + connectionFactory.setPort(rabbitmqProperties.port()); + connectionFactory.setUsername(rabbitmqProperties.userName()); + connectionFactory.setPassword(rabbitmqProperties.password()); + connectionFactory.setVirtualHost(rabbitmqProperties.virtualHost()); + connectionFactory.setPublisherConfirmType(rabbitmqProperties.publisherConfirmType()); + connectionFactory.setPublisherReturns(rabbitmqProperties.publisherReturns()); + + if (rabbitmqProperties.isSslEnabled()) { + try { + connectionFactory.getRabbitConnectionFactory().useSslProtocol(); + } catch (NoSuchAlgorithmException | KeyManagementException e) { + throw new InternalServerException(e); + } + } return connectionFactory; } diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/global/config/rabbitmq/RabbitmqProperties.java b/backend/core/src/main/java/site/timecapsulearchive/core/global/config/rabbitmq/RabbitmqProperties.java new file mode 100644 index 00000000..a8e11e84 --- /dev/null +++ b/backend/core/src/main/java/site/timecapsulearchive/core/global/config/rabbitmq/RabbitmqProperties.java @@ -0,0 +1,28 @@ +package site.timecapsulearchive.core.global.config.rabbitmq; + +import org.springframework.amqp.rabbit.connection.CachingConnectionFactory.ConfirmType; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.context.properties.NestedConfigurationProperty; + +@ConfigurationProperties(prefix = "spring.rabbitmq") +public record RabbitmqProperties( + String host, + int port, + String userName, + String password, + String virtualHost, + ConfirmType publisherConfirmType, + boolean publisherReturns, + @NestedConfigurationProperty + SSL ssl +) { + protected record SSL( + boolean enabled + ) { + + } + + public boolean isSslEnabled() { + return ssl != null && ssl.enabled; + } +} \ No newline at end of file From 14cc61e2bb1ef34d0662b62f9a4d34d88656fc10 Mon Sep 17 00:00:00 2001 From: hong seokho Date: Tue, 30 Jul 2024 12:36:40 +0900 Subject: [PATCH 2/2] =?UTF-8?q?fix=20:=20logback=20container=20=ED=99=98?= =?UTF-8?q?=EA=B2=BD=20loki=20=EC=A0=9C=EC=99=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/core/src/main/resources/logback-spring.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/core/src/main/resources/logback-spring.xml b/backend/core/src/main/resources/logback-spring.xml index 61e3d86a..f9ba2a0c 100644 --- a/backend/core/src/main/resources/logback-spring.xml +++ b/backend/core/src/main/resources/logback-spring.xml @@ -31,7 +31,7 @@ - + @@ -43,7 +43,7 @@ - +