From 65624ef4f0728eff7853d371ec33873f7c5347ce Mon Sep 17 00:00:00 2001 From: takoyakimchi Date: Sun, 1 Dec 2024 16:57:08 +0900 Subject: [PATCH 1/4] =?UTF-8?q?chore:=20=EB=8B=A8=EC=9D=BC=20DB=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=ED=95=98=EB=8A=94=20=EB=B0=A9=EC=8B=9D?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/datasource/DataSourceConfig.java | 2 +- .../ReplicationRoutingDataSource.java | 2 +- .../src/main/resources/application-prod.yml | 20 ++++++------------- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/backend/src/main/java/com/happy/friendogly/config/datasource/DataSourceConfig.java b/backend/src/main/java/com/happy/friendogly/config/datasource/DataSourceConfig.java index 0ea431857..8d9ae1284 100644 --- a/backend/src/main/java/com/happy/friendogly/config/datasource/DataSourceConfig.java +++ b/backend/src/main/java/com/happy/friendogly/config/datasource/DataSourceConfig.java @@ -13,7 +13,7 @@ import org.springframework.context.annotation.Profile; import org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy; -@Profile("prod") +@Profile("prod-replication") @Configuration public class DataSourceConfig { diff --git a/backend/src/main/java/com/happy/friendogly/config/datasource/ReplicationRoutingDataSource.java b/backend/src/main/java/com/happy/friendogly/config/datasource/ReplicationRoutingDataSource.java index 70e14e81c..73622c81f 100644 --- a/backend/src/main/java/com/happy/friendogly/config/datasource/ReplicationRoutingDataSource.java +++ b/backend/src/main/java/com/happy/friendogly/config/datasource/ReplicationRoutingDataSource.java @@ -4,7 +4,7 @@ import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource; import org.springframework.transaction.support.TransactionSynchronizationManager; -@Profile("prod") +@Profile("prod-replication") public class ReplicationRoutingDataSource extends AbstractRoutingDataSource { @Override diff --git a/backend/src/main/resources/application-prod.yml b/backend/src/main/resources/application-prod.yml index a85d1aab7..d1c7e476c 100644 --- a/backend/src/main/resources/application-prod.yml +++ b/backend/src/main/resources/application-prod.yml @@ -41,21 +41,13 @@ spring: sql: init: data-locations: + datasource: - writer: - hikari: - driver-class-name: com.mysql.cj.jdbc.Driver - jdbc-url: ${WRITER_MYSQL_URL} - read-only: false - username: ${MYSQL_USERNAME} - password: ${MYSQL_PASSWORD} - reader: - hikari: - driver-class-name: com.mysql.cj.jdbc.Driver - jdbc-url: ${READER_MYSQL_URL} - read-only: true - username: ${MYSQL_USERNAME} - password: ${MYSQL_PASSWORD} + driver-class-name: com.mysql.cj.jdbc.Driver + url: ${MYSQL_PROD_RDS_URL} + username: ${MYSQL_PROD_RDS_USERNAME} + password: ${MYSQL_PROD_RDS_PASSWORD} + jpa: hibernate: ddl-auto: validate From 11014b416fe08ed5709655c85a646d548288d10e Mon Sep 17 00:00:00 2001 From: takoyakimchi Date: Sun, 1 Dec 2024 17:25:49 +0900 Subject: [PATCH 2/4] =?UTF-8?q?chore:=20RabbitMQ=20->=20=EC=9D=B8=EB=A9=94?= =?UTF-8?q?=EB=AA=A8=EB=A6=AC=20=EB=A9=94=EC=8B=9C=EC=A7=80=20=EB=B8=8C?= =?UTF-8?q?=EB=A1=9C=EC=BB=A4=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../friendogly/chatsocket/config/RabbitMqConfig.java | 2 +- ...etLocalConfig.java => WebSocketInMemoryConfig.java} | 6 +++--- .../chatsocket/config/WebSocketRabbitMqConfig.java | 2 +- .../chatsocket/template/InMemoryChatTemplate.java | 2 +- .../chatsocket/template/RabbitChatTemplate.java | 2 +- backend/src/main/resources/application-dev.yml | 5 +++++ backend/src/main/resources/application-local.yml | 1 + backend/src/main/resources/application-prod.yml | 10 ++++------ 8 files changed, 17 insertions(+), 13 deletions(-) rename backend/src/main/java/com/happy/friendogly/chatsocket/config/{WebSocketLocalConfig.java => WebSocketInMemoryConfig.java} (93%) diff --git a/backend/src/main/java/com/happy/friendogly/chatsocket/config/RabbitMqConfig.java b/backend/src/main/java/com/happy/friendogly/chatsocket/config/RabbitMqConfig.java index d15810913..67a87c2b5 100644 --- a/backend/src/main/java/com/happy/friendogly/chatsocket/config/RabbitMqConfig.java +++ b/backend/src/main/java/com/happy/friendogly/chatsocket/config/RabbitMqConfig.java @@ -26,7 +26,7 @@ @Configuration @EnableRabbit -@Profile("!local") +@Profile("rabbit") public class RabbitMqConfig { private static final String CHAT_QUEUE_NAME = "chat.queue"; diff --git a/backend/src/main/java/com/happy/friendogly/chatsocket/config/WebSocketLocalConfig.java b/backend/src/main/java/com/happy/friendogly/chatsocket/config/WebSocketInMemoryConfig.java similarity index 93% rename from backend/src/main/java/com/happy/friendogly/chatsocket/config/WebSocketLocalConfig.java rename to backend/src/main/java/com/happy/friendogly/chatsocket/config/WebSocketInMemoryConfig.java index b3e43a205..a954b0344 100644 --- a/backend/src/main/java/com/happy/friendogly/chatsocket/config/WebSocketLocalConfig.java +++ b/backend/src/main/java/com/happy/friendogly/chatsocket/config/WebSocketInMemoryConfig.java @@ -12,16 +12,16 @@ import org.springframework.web.socket.config.annotation.StompEndpointRegistry; import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; -@Profile("local") +@Profile("local | dev | prod") @Configuration @EnableWebSocketMessageBroker -public class WebSocketLocalConfig implements WebSocketMessageBrokerConfigurer { +public class WebSocketInMemoryConfig implements WebSocketMessageBrokerConfigurer { private final WebSocketInterceptor webSocketInterceptor; private final WebSocketErrorHandler webSocketErrorHandler; private final JwtProvider jwtProvider; - public WebSocketLocalConfig( + public WebSocketInMemoryConfig( WebSocketInterceptor webSocketInterceptor, WebSocketErrorHandler webSocketErrorHandler, JwtProvider jwtProvider diff --git a/backend/src/main/java/com/happy/friendogly/chatsocket/config/WebSocketRabbitMqConfig.java b/backend/src/main/java/com/happy/friendogly/chatsocket/config/WebSocketRabbitMqConfig.java index cdabc51a6..ad4f324a3 100644 --- a/backend/src/main/java/com/happy/friendogly/chatsocket/config/WebSocketRabbitMqConfig.java +++ b/backend/src/main/java/com/happy/friendogly/chatsocket/config/WebSocketRabbitMqConfig.java @@ -14,7 +14,7 @@ import org.springframework.web.socket.config.annotation.StompEndpointRegistry; import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; -@Profile("!local") +@Profile("rabbit") @Configuration @EnableWebSocketMessageBroker public class WebSocketRabbitMqConfig implements WebSocketMessageBrokerConfigurer { diff --git a/backend/src/main/java/com/happy/friendogly/chatsocket/template/InMemoryChatTemplate.java b/backend/src/main/java/com/happy/friendogly/chatsocket/template/InMemoryChatTemplate.java index 4423b204e..a781c7775 100644 --- a/backend/src/main/java/com/happy/friendogly/chatsocket/template/InMemoryChatTemplate.java +++ b/backend/src/main/java/com/happy/friendogly/chatsocket/template/InMemoryChatTemplate.java @@ -5,7 +5,7 @@ import org.springframework.stereotype.Component; @Component -@Profile("local") +@Profile("local | dev | prod") public class InMemoryChatTemplate implements ChatTemplate { private static final String TOPIC_CHAT_PREFIX = "/exchange/chat.exchange/room."; diff --git a/backend/src/main/java/com/happy/friendogly/chatsocket/template/RabbitChatTemplate.java b/backend/src/main/java/com/happy/friendogly/chatsocket/template/RabbitChatTemplate.java index 3ba46d29a..8e244720f 100644 --- a/backend/src/main/java/com/happy/friendogly/chatsocket/template/RabbitChatTemplate.java +++ b/backend/src/main/java/com/happy/friendogly/chatsocket/template/RabbitChatTemplate.java @@ -5,7 +5,7 @@ import org.springframework.stereotype.Component; @Component -@Profile("!local") +@Profile("rabbit") public class RabbitChatTemplate implements ChatTemplate { private final RabbitTemplate rabbitTemplate; diff --git a/backend/src/main/resources/application-dev.yml b/backend/src/main/resources/application-dev.yml index 08a713b84..5c43a4c94 100644 --- a/backend/src/main/resources/application-dev.yml +++ b/backend/src/main/resources/application-dev.yml @@ -37,3 +37,8 @@ spring: sql: init: data-locations: + +management: + health: + rabbit: + enabled: false diff --git a/backend/src/main/resources/application-local.yml b/backend/src/main/resources/application-local.yml index 4c280fb8f..c42b23830 100644 --- a/backend/src/main/resources/application-local.yml +++ b/backend/src/main/resources/application-local.yml @@ -30,6 +30,7 @@ logging.level.org: file: firebase: path: firebase-friendogly-private-key.json + management: health: rabbit: diff --git a/backend/src/main/resources/application-prod.yml b/backend/src/main/resources/application-prod.yml index d1c7e476c..d45668512 100644 --- a/backend/src/main/resources/application-prod.yml +++ b/backend/src/main/resources/application-prod.yml @@ -27,17 +27,15 @@ management: server: port: 8081 + health: + rabbit: + enabled: false + file: firebase: path: firebase-friendogly-private-key.json spring: - rabbitmq: - host: ${RABBITMQ_PROD_HOST} - username: ${RABBITMQ_PROD_USERNAME} - password: ${RABBITMQ_PROD_PASSWORD} - port: 3100 # initial connection port: use 3100 instead of 5672 - stomp-port: 9100 # STOMP port: use 9100 instead of 61613 sql: init: data-locations: From aee029abbac63f95843d00b1928df0fdd4d310e8 Mon Sep 17 00:00:00 2001 From: takoyakimchi Date: Tue, 3 Dec 2024 15:40:23 +0900 Subject: [PATCH 3/4] =?UTF-8?q?refactor:=20`@Profile`=20=EB=AA=85=EC=8B=9C?= =?UTF-8?q?=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../friendogly/chatsocket/config/WebSocketInMemoryConfig.java | 2 -- .../friendogly/chatsocket/config/WebSocketRabbitMqConfig.java | 2 +- .../friendogly/chatsocket/template/InMemoryChatTemplate.java | 2 -- .../friendogly/chatsocket/template/RabbitChatTemplate.java | 2 +- 4 files changed, 2 insertions(+), 6 deletions(-) diff --git a/backend/src/main/java/com/happy/friendogly/chatsocket/config/WebSocketInMemoryConfig.java b/backend/src/main/java/com/happy/friendogly/chatsocket/config/WebSocketInMemoryConfig.java index a954b0344..4d41829e3 100644 --- a/backend/src/main/java/com/happy/friendogly/chatsocket/config/WebSocketInMemoryConfig.java +++ b/backend/src/main/java/com/happy/friendogly/chatsocket/config/WebSocketInMemoryConfig.java @@ -4,7 +4,6 @@ import com.happy.friendogly.auth.service.jwt.JwtProvider; import java.util.List; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Profile; import org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver; import org.springframework.messaging.simp.config.ChannelRegistration; import org.springframework.messaging.simp.config.MessageBrokerRegistry; @@ -12,7 +11,6 @@ import org.springframework.web.socket.config.annotation.StompEndpointRegistry; import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; -@Profile("local | dev | prod") @Configuration @EnableWebSocketMessageBroker public class WebSocketInMemoryConfig implements WebSocketMessageBrokerConfigurer { diff --git a/backend/src/main/java/com/happy/friendogly/chatsocket/config/WebSocketRabbitMqConfig.java b/backend/src/main/java/com/happy/friendogly/chatsocket/config/WebSocketRabbitMqConfig.java index ad4f324a3..0c1db62cf 100644 --- a/backend/src/main/java/com/happy/friendogly/chatsocket/config/WebSocketRabbitMqConfig.java +++ b/backend/src/main/java/com/happy/friendogly/chatsocket/config/WebSocketRabbitMqConfig.java @@ -14,7 +14,7 @@ import org.springframework.web.socket.config.annotation.StompEndpointRegistry; import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; -@Profile("rabbit") +@Profile("rabbit") // RabbitMQ가 필요한 상황에서는 해당 프로파일명을 변경해주세요. @Configuration @EnableWebSocketMessageBroker public class WebSocketRabbitMqConfig implements WebSocketMessageBrokerConfigurer { diff --git a/backend/src/main/java/com/happy/friendogly/chatsocket/template/InMemoryChatTemplate.java b/backend/src/main/java/com/happy/friendogly/chatsocket/template/InMemoryChatTemplate.java index a781c7775..d9c5a9911 100644 --- a/backend/src/main/java/com/happy/friendogly/chatsocket/template/InMemoryChatTemplate.java +++ b/backend/src/main/java/com/happy/friendogly/chatsocket/template/InMemoryChatTemplate.java @@ -1,11 +1,9 @@ package com.happy.friendogly.chatsocket.template; -import org.springframework.context.annotation.Profile; import org.springframework.messaging.simp.SimpMessagingTemplate; import org.springframework.stereotype.Component; @Component -@Profile("local | dev | prod") public class InMemoryChatTemplate implements ChatTemplate { private static final String TOPIC_CHAT_PREFIX = "/exchange/chat.exchange/room."; diff --git a/backend/src/main/java/com/happy/friendogly/chatsocket/template/RabbitChatTemplate.java b/backend/src/main/java/com/happy/friendogly/chatsocket/template/RabbitChatTemplate.java index 8e244720f..8bc7972a3 100644 --- a/backend/src/main/java/com/happy/friendogly/chatsocket/template/RabbitChatTemplate.java +++ b/backend/src/main/java/com/happy/friendogly/chatsocket/template/RabbitChatTemplate.java @@ -5,7 +5,7 @@ import org.springframework.stereotype.Component; @Component -@Profile("rabbit") +@Profile("rabbit") // RabbitMQ가 필요한 상황에서는 해당 프로파일명을 변경해주세요. public class RabbitChatTemplate implements ChatTemplate { private final RabbitTemplate rabbitTemplate; From 349697ff7ede8db5bfeb6223af5544bae0b7ee0b Mon Sep 17 00:00:00 2001 From: takoyakimchi Date: Tue, 3 Dec 2024 16:04:02 +0900 Subject: [PATCH 4/4] =?UTF-8?q?comment:=20DB=20replication=20=ED=99=98?= =?UTF-8?q?=EA=B2=BD=20=EA=B4=80=EB=A0=A8=20=EC=A3=BC=EC=84=9D=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../happy/friendogly/config/datasource/DataSourceConfig.java | 2 +- .../config/datasource/ReplicationRoutingDataSource.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/com/happy/friendogly/config/datasource/DataSourceConfig.java b/backend/src/main/java/com/happy/friendogly/config/datasource/DataSourceConfig.java index 8d9ae1284..28924210e 100644 --- a/backend/src/main/java/com/happy/friendogly/config/datasource/DataSourceConfig.java +++ b/backend/src/main/java/com/happy/friendogly/config/datasource/DataSourceConfig.java @@ -13,7 +13,7 @@ import org.springframework.context.annotation.Profile; import org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy; -@Profile("prod-replication") +@Profile("prod-replication") // DB 이중화하는 경우 프로파일명을 변경해주세요. @Configuration public class DataSourceConfig { diff --git a/backend/src/main/java/com/happy/friendogly/config/datasource/ReplicationRoutingDataSource.java b/backend/src/main/java/com/happy/friendogly/config/datasource/ReplicationRoutingDataSource.java index 73622c81f..d41b8d412 100644 --- a/backend/src/main/java/com/happy/friendogly/config/datasource/ReplicationRoutingDataSource.java +++ b/backend/src/main/java/com/happy/friendogly/config/datasource/ReplicationRoutingDataSource.java @@ -4,7 +4,7 @@ import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource; import org.springframework.transaction.support.TransactionSynchronizationManager; -@Profile("prod-replication") +@Profile("prod-replication") // DB 이중화하는 경우 프로파일명을 변경해주세요. public class ReplicationRoutingDataSource extends AbstractRoutingDataSource { @Override