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 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 @@ - +