Skip to content

Commit

Permalink
Merge pull request #620 from tukcomCD2024/feat/setup_logging-B-#618
Browse files Browse the repository at this point in the history
feat : 알림서버 AOP로 추적 로깅 추가 #618
  • Loading branch information
seokho-1116 authored Aug 11, 2024
2 parents c1e2b7d + e2365d2 commit 0deeb62
Show file tree
Hide file tree
Showing 22 changed files with 363 additions and 123 deletions.
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
package site.timecapsulearchive.notification.global.config;
package site.timecapsulearchive.notification.global.config.rabbitmq;

import java.util.Arrays;
import lombok.Getter;

@Getter
public enum RabbitmqComponentConstants {

CAPSULE_SKIN_QUEUE("notification.createCapsuleSkin.queue",
CAPSULE_SKIN_NOTIFICATION_QUEUE("notification.createCapsuleSkin.queue",
"fail.notification.createCapsuleSkin.queue"),
CAPSULE_SKIN_EXCHANGE("notification.createCapsuleSkin.exchange",
CAPSULE_SKIN_NOTIFICATION_EXCHANGE("notification.createCapsuleSkin.exchange",
"fail.notification.createCapsuleSkin.exchange"),
FRIEND_REQUEST_NOTIFICATION_QUEUE("notification.friendRequest.queue",
"fail.notification.friendRequest.queue"),
FRIEND_REQUEST_NOTIFICATION_EXCHANGE("notification.friendRequest.exchange",
"fail.notification.friendRequest.exchange"),
FRIEND_REQUESTS_NOTIFICATION_QUEUE("notification.friendRequests.queue",
"fail.notification.friendRequests.queue"),
FRIEND_REQUESTS_NOTIFICATION_EXCHANGE("notification.friendRequests.exchange",
"fail.notification.friendRequests.exchange"),
BATCH_FRIEND_REQUESTS_NOTIFICATION_QUEUE("batch.notification.friendRequests.queue",
"fail.batch.notification.friendRequests.queue"),
BATCH_FRIEND_REQUESTS_NOTIFICATION_EXCHANGE("batch.notification.friendRequests.exchange",
"fail.batch.notification.friendRequests.exchange"),
FRIEND_ACCEPT_NOTIFICATION_QUEUE("notification.friendAccept.queue",
"fail.notification.friendAccept.queue"),
FRIEND_ACCEPT_NOTIFICATION_EXCHANGE("notification.friendAccept.exchange",
"fail.notification.friendAccept.exchange"),
GROUP_INVITE_QUEUE("notification.groupInvite.queue", "fail.notification.groupInvite.queue"),
GROUP_INVITE_EXCHANGE("notification.groupInvite.exchange",
GROUP_INVITE_NOTIFICATION_QUEUE("notification.groupInvite.queue",
"fail.notification.groupInvite.queue"),
GROUP_INVITE_NOTIFICATION_EXCHANGE("notification.groupInvite.exchange",
"fail.notification.groupInvite.exchange"),
GROUP_ACCEPT_NOTIFICATION_QUEUE("notification.groupAccept.queue",
"fail.notification.groupAccept.queue"),
Expand All @@ -37,12 +38,4 @@ public enum RabbitmqComponentConstants {
this.successComponent = successComponent;
this.failComponent = failComponent;
}

public static String getFailComponent(String successComponent) {
return Arrays.stream(RabbitmqComponentConstants.values())
.filter(constants -> constants.getSuccessComponent().equals(successComponent))
.map(RabbitmqComponentConstants::getFailComponent)
.toList()
.get(0);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package site.timecapsulearchive.notification.global.config;
package site.timecapsulearchive.notification.global.config.rabbitmq;

import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
Expand All @@ -7,7 +7,9 @@
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.QueueBuilder;
import org.springframework.amqp.rabbit.annotation.EnableRabbit;
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
Expand All @@ -24,13 +26,17 @@ public class RabbitmqConfig {

@Bean
public Queue capsuleSkinQueue() {
return new Queue(RabbitmqComponentConstants.CAPSULE_SKIN_QUEUE.getSuccessComponent(), true);
return QueueBuilder.durable(
RabbitmqComponentConstants.CAPSULE_SKIN_NOTIFICATION_QUEUE.getSuccessComponent())
.withArgument("x-dead-letter-exchange",
RabbitmqComponentConstants.CAPSULE_SKIN_NOTIFICATION_EXCHANGE.getFailComponent())
.build();
}

@Bean
public DirectExchange capsuleSkinExchange() {
return new DirectExchange(
RabbitmqComponentConstants.CAPSULE_SKIN_EXCHANGE.getSuccessComponent());
RabbitmqComponentConstants.CAPSULE_SKIN_NOTIFICATION_EXCHANGE.getSuccessComponent());
}

@Bean
Expand All @@ -43,13 +49,17 @@ public Binding capsuleSkinBinding() {

@Bean
public Queue groupInviteQueue() {
return new Queue(RabbitmqComponentConstants.GROUP_INVITE_QUEUE.getSuccessComponent(), true);
return QueueBuilder.durable(
RabbitmqComponentConstants.GROUP_INVITE_NOTIFICATION_QUEUE.getSuccessComponent())
.withArgument("x-dead-letter-exchange",
RabbitmqComponentConstants.GROUP_INVITE_NOTIFICATION_EXCHANGE.getFailComponent())
.build();
}

@Bean
public DirectExchange groupInviteExchange() {
return new DirectExchange(
RabbitmqComponentConstants.GROUP_INVITE_EXCHANGE.getSuccessComponent());
RabbitmqComponentConstants.GROUP_INVITE_NOTIFICATION_EXCHANGE.getSuccessComponent());
}

@Bean
Expand All @@ -62,8 +72,11 @@ public Binding groupInviteBinding() {

@Bean
public Queue groupAcceptQueue() {
return new Queue(
RabbitmqComponentConstants.GROUP_ACCEPT_NOTIFICATION_QUEUE.getSuccessComponent(), true);
return QueueBuilder.durable(
RabbitmqComponentConstants.GROUP_ACCEPT_NOTIFICATION_QUEUE.getSuccessComponent())
.withArgument("x-dead-letter-exchange",
RabbitmqComponentConstants.GROUP_ACCEPT_NOTIFICATION_EXCHANGE.getFailComponent())
.build();
}

@Bean
Expand All @@ -82,9 +95,11 @@ public Binding groupAcceptBinding() {

@Bean
public Queue friendRequestQueue() {
return new Queue(
RabbitmqComponentConstants.FRIEND_REQUEST_NOTIFICATION_QUEUE.getSuccessComponent(),
true);
return QueueBuilder.durable(
RabbitmqComponentConstants.FRIEND_REQUEST_NOTIFICATION_QUEUE.getSuccessComponent())
.withArgument("x-dead-letter-exchange",
RabbitmqComponentConstants.FRIEND_REQUEST_NOTIFICATION_EXCHANGE.getFailComponent())
.build();
}

@Bean
Expand All @@ -103,9 +118,11 @@ public Binding friendRequestBinding() {

@Bean
public Queue friendAcceptQueue() {
return new Queue(
RabbitmqComponentConstants.FRIEND_ACCEPT_NOTIFICATION_QUEUE.getSuccessComponent(),
true);
return QueueBuilder.durable(
RabbitmqComponentConstants.FRIEND_ACCEPT_NOTIFICATION_QUEUE.getSuccessComponent())
.withArgument("x-dead-letter-exchange",
RabbitmqComponentConstants.FRIEND_ACCEPT_NOTIFICATION_EXCHANGE.getFailComponent())
.build();
}

@Bean
Expand All @@ -123,18 +140,41 @@ public Binding friendAcceptBinding() {
}

@Bean
public RabbitTemplate rabbitTemplate() {
RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory());
rabbitTemplate.setMessageConverter(jsonMessageConverter());
public Queue batchFriendRequestsQueue() {
return QueueBuilder.durable(
RabbitmqComponentConstants.BATCH_FRIEND_REQUESTS_NOTIFICATION_QUEUE.getSuccessComponent())
.withArgument("x-dead-letter-exchange",
RabbitmqComponentConstants.BATCH_FRIEND_REQUESTS_NOTIFICATION_EXCHANGE.getFailComponent())
.build();
}

return rabbitTemplate;
@Bean
public DirectExchange batchFriendRequestsExchange() {
return new DirectExchange(
RabbitmqComponentConstants.BATCH_FRIEND_REQUESTS_NOTIFICATION_EXCHANGE.getSuccessComponent());
}

@Bean
public Binding batchFriendRequestsBinding() {
return BindingBuilder
.bind(batchFriendRequestsQueue())
.to(batchFriendRequestsExchange())
.withQueueName();
}

@Bean
public Jackson2JsonMessageConverter jsonMessageConverter() {
return new Jackson2JsonMessageConverter();
}

@Bean
public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory() {
SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
factory.setConnectionFactory(connectionFactory());
factory.setMessageConverter(jsonMessageConverter());
return factory;
}

@Bean
public CachingConnectionFactory connectionFactory() {
CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
Expand All @@ -155,4 +195,11 @@ public CachingConnectionFactory connectionFactory() {

return connectionFactory;
}

@Bean
public RabbitTemplate rabbitTemplate() {
RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory());
rabbitTemplate.setMessageConverter(jsonMessageConverter());
return rabbitTemplate;
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package site.timecapsulearchive.notification.global.config;
package site.timecapsulearchive.notification.global.config.rabbitmq;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -12,40 +12,40 @@ public class RabbitmqFailComponentConfig {

@Bean
public Queue capsuleSkinFailQueue() {
return new Queue(RabbitmqComponentConstants.CAPSULE_SKIN_QUEUE.getFailComponent(), true);
return new Queue(
RabbitmqComponentConstants.CAPSULE_SKIN_NOTIFICATION_QUEUE.getFailComponent(), true);
}

@Bean
public DirectExchange capsuleSkinFailExchange() {
return new DirectExchange(
RabbitmqComponentConstants.CAPSULE_SKIN_EXCHANGE.getFailComponent());
public FanoutExchange capsuleSkinFailExchange() {
return new FanoutExchange(
RabbitmqComponentConstants.CAPSULE_SKIN_NOTIFICATION_EXCHANGE.getFailComponent());
}

@Bean
public Binding capsuleSkinFailBinding() {
return BindingBuilder
.bind(capsuleSkinFailQueue())
.to(capsuleSkinFailExchange())
.withQueueName();
.to(capsuleSkinFailExchange());
}

@Bean
public Queue groupInviteFailQueue() {
return new Queue(RabbitmqComponentConstants.GROUP_INVITE_QUEUE.getFailComponent(), true);
return new Queue(
RabbitmqComponentConstants.GROUP_INVITE_NOTIFICATION_QUEUE.getFailComponent(), true);
}

@Bean
public DirectExchange groupInviteFailExchange() {
return new DirectExchange(
RabbitmqComponentConstants.GROUP_INVITE_EXCHANGE.getFailComponent());
public FanoutExchange groupInviteFailExchange() {
return new FanoutExchange(
RabbitmqComponentConstants.GROUP_INVITE_NOTIFICATION_EXCHANGE.getFailComponent());
}

@Bean
public Binding groupInviteFailBinding() {
return BindingBuilder
.bind(groupInviteFailQueue())
.to(groupInviteFailExchange())
.withQueueName();
.to(groupInviteFailExchange());
}


Expand All @@ -56,17 +56,16 @@ public Queue groupAcceptFailQueue() {
}

@Bean
public DirectExchange groupAcceptFailExchange() {
return new DirectExchange(
public FanoutExchange groupAcceptFailExchange() {
return new FanoutExchange(
RabbitmqComponentConstants.GROUP_ACCEPT_NOTIFICATION_EXCHANGE.getFailComponent());
}

@Bean
public Binding groupAcceptFailBinding() {
return BindingBuilder
.bind(groupAcceptFailQueue())
.to(groupAcceptFailExchange())
.withQueueName();
.to(groupAcceptFailExchange());
}


Expand All @@ -78,17 +77,16 @@ public Queue friendRequestFailQueue() {
}

@Bean
public DirectExchange friendRequestFailExchange() {
return new DirectExchange(
public FanoutExchange friendRequestFailExchange() {
return new FanoutExchange(
RabbitmqComponentConstants.FRIEND_REQUEST_NOTIFICATION_EXCHANGE.getFailComponent());
}

@Bean
public Binding friendRequestFailBinding() {
return BindingBuilder
.bind(friendRequestFailQueue())
.to(friendRequestFailExchange())
.withQueueName();
.to(friendRequestFailExchange());
}

@Bean
Expand All @@ -99,16 +97,35 @@ public Queue friendAcceptFailQueue() {
}

@Bean
public DirectExchange friendAcceptFailExchange() {
return new DirectExchange(
public FanoutExchange friendAcceptFailExchange() {
return new FanoutExchange(
RabbitmqComponentConstants.FRIEND_ACCEPT_NOTIFICATION_EXCHANGE.getFailComponent());
}

@Bean
public Binding friendAcceptFailBinding() {
return BindingBuilder
.bind(friendAcceptFailQueue())
.to(friendAcceptFailExchange())
.withQueueName();
.to(friendAcceptFailExchange());
}

@Bean
public Queue batchFriendRequestsFailQueue() {
return new Queue(
RabbitmqComponentConstants.BATCH_FRIEND_REQUESTS_NOTIFICATION_QUEUE.getFailComponent(),
true);
}

@Bean
public FanoutExchange batchFriendRequestsFailExchange() {
return new FanoutExchange(
RabbitmqComponentConstants.BATCH_FRIEND_REQUESTS_NOTIFICATION_EXCHANGE.getFailComponent());
}

@Bean
public Binding batchFriendRequestsFailBinding() {
return BindingBuilder
.bind(batchFriendRequestsFailQueue())
.to(batchFriendRequestsFailExchange());
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package site.timecapsulearchive.notification.global.config;
package site.timecapsulearchive.notification.global.config.rabbitmq;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
Expand Down
Loading

0 comments on commit 0deeb62

Please sign in to comment.