Skip to content

Commit

Permalink
Merge pull request #596 from tukcomCD2024/fix/rabbitmq_config-core-B-…
Browse files Browse the repository at this point in the history
…#595

fix : rabbitmq ssl 설정 추가 #595
  • Loading branch information
seokho-1116 authored Jul 30, 2024
2 parents 2ef67ca + 14cc61e commit b2d87ed
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
4 changes: 2 additions & 2 deletions backend/core/src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</encoder>
</appender>

<springProfile name="prod | container">
<springProfile name="prod">
<logger name="org.hibernate" level="error" additivity="false">
<appender-ref ref="STDOUT"/>
<appender-ref ref="LOKI"/>
Expand All @@ -43,7 +43,7 @@
</root>
</springProfile>

<springProfile name="local | dev | test">
<springProfile name="local | dev | test | container">
<logger name="org.hibernate" level="error" additivity="false">
<appender-ref ref="STDOUT"/>
</logger>
Expand Down

0 comments on commit b2d87ed

Please sign in to comment.