-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d3abada
commit 05037f1
Showing
518 changed files
with
4,757 additions
and
2,220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,4 @@ | ||
# Build - https://findstar.pe.kr/2022/05/13/gradle-docker-cache/ | ||
FROM gradle:8.6.0-jdk17 as builder | ||
WORKDIR /build | ||
|
||
# 그레이들 파일이 변경되었을 때만 새로운 의존성 다운로드 | ||
COPY build.gradle settings.gradle /build/ | ||
COPY alarm-api/build.gradle /build/alarm-api/ | ||
RUN gradle build -x test --parallel --continue > /dev/null 2>&1 || true | ||
|
||
# 빌더 이미지에서 애플리케이션 빌드 | ||
COPY . /build | ||
RUN gradle build -x test --parallel | ||
|
||
# Run | ||
FROM openjdk:17-jdk-slim | ||
WORKDIR /app | ||
|
||
COPY --from=builder /build/alarm-api/build/libs/*.jar app.jar | ||
|
||
ARG DOCKER_YML_FILE=src/main/resources/application.yml | ||
COPY ${DOCKER_YML_FILE} application.yml | ||
|
||
EXPOSE 28000 | ||
|
||
ENTRYPOINT ["java", "-jar", "app.jar"] | ||
ARG JAR_FILE=build/libs/*.jar | ||
ADD ${JAR_FILE} app.jar | ||
ENTRYPOINT ["java", "-jar", "/app.jar"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
src/backend/alarm-server/alarm-api/src/main/java/com/lalala/alarm/config/RabbitMQConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package com.lalala.alarm.config; | ||
|
||
import org.springframework.amqp.core.*; | ||
import org.springframework.amqp.rabbit.connection.ConnectionFactory; | ||
import org.springframework.amqp.rabbit.core.RabbitTemplate; | ||
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.messaging.converter.MappingJackson2MessageConverter; | ||
import org.springframework.messaging.handler.annotation.support.DefaultMessageHandlerMethodFactory; | ||
import org.springframework.messaging.handler.annotation.support.MessageHandlerMethodFactory; | ||
|
||
@Configuration | ||
public class RabbitMQConfig { | ||
|
||
private static final String EXCHANGE_NAME = "retry-exchange"; | ||
public static final String QUEUE = "mainQueue"; | ||
private static final String RETRY_QUEUE = "mainQueue.retry"; | ||
public static final String UNDELIVERED_QUEUE = "mainQueue.undelivered"; | ||
private static final String MAIN_ROUTING_KEY = "Routing_Key"; | ||
|
||
@Value("${rabbitmq.retry.delay-in-ms}") | ||
private Integer retryDelay; | ||
|
||
@Bean | ||
public RabbitTemplate rabbitTemplate(final ConnectionFactory connectionFactory) { | ||
final RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory); | ||
rabbitTemplate.setMessageConverter(producerJackson2MessageConverter()); | ||
return rabbitTemplate; | ||
} | ||
|
||
@Bean | ||
MessageHandlerMethodFactory messageHandlerMethodFactory() { | ||
DefaultMessageHandlerMethodFactory messageHandlerMethodFactory = new DefaultMessageHandlerMethodFactory(); | ||
messageHandlerMethodFactory.setMessageConverter(new MappingJackson2MessageConverter()); | ||
return messageHandlerMethodFactory; | ||
} | ||
|
||
@Bean | ||
public Jackson2JsonMessageConverter producerJackson2MessageConverter() { | ||
return new Jackson2JsonMessageConverter(); | ||
} | ||
|
||
@Bean | ||
TopicExchange exchange() { | ||
return new TopicExchange(EXCHANGE_NAME); | ||
} | ||
|
||
@Bean | ||
Queue mainQueue() { | ||
return QueueBuilder.durable(QUEUE) | ||
.deadLetterExchange(EXCHANGE_NAME) | ||
.deadLetterRoutingKey(RETRY_QUEUE) | ||
.quorum() | ||
.build(); | ||
} | ||
|
||
@Bean | ||
Queue retryQueue() { | ||
return QueueBuilder.durable(RETRY_QUEUE) | ||
.deadLetterExchange(EXCHANGE_NAME) | ||
.deadLetterRoutingKey(MAIN_ROUTING_KEY) | ||
.ttl(retryDelay) | ||
.quorum() | ||
.build(); | ||
} | ||
|
||
@Bean | ||
Queue undeliveredQueue() { | ||
return QueueBuilder.durable(UNDELIVERED_QUEUE) | ||
.quorum() | ||
.build(); | ||
} | ||
|
||
@Bean | ||
Binding mainBinding(Queue mainQueue, TopicExchange exchange) { | ||
return BindingBuilder.bind(mainQueue).to(exchange).with(MAIN_ROUTING_KEY); | ||
} | ||
|
||
@Bean | ||
Binding retryBinding(Queue retryQueue, TopicExchange exchange) { | ||
return BindingBuilder.bind(retryQueue).to(exchange).with(RETRY_QUEUE); | ||
} | ||
|
||
@Bean | ||
Binding undeliveredBinding(Queue undeliveredQueue, TopicExchange exchange) { | ||
return BindingBuilder.bind(undeliveredQueue).to(exchange).with(UNDELIVERED_QUEUE); | ||
} | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
src/backend/alarm-server/alarm-api/src/main/java/com/lalala/alarm/dto/Email.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.lalala.alarm.dto; | ||
|
||
import lombok.Data; | ||
import lombok.ToString; | ||
|
||
@Data | ||
@ToString | ||
public class Email { | ||
|
||
private String subject; | ||
private String recipient; | ||
private String content; | ||
} |
53 changes: 53 additions & 0 deletions
53
...larm-server/alarm-api/src/main/java/com/lalala/alarm/listener/RetryingRabbitListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.lalala.alarm.listener; | ||
|
||
import static com.lalala.alarm.config.RabbitMQConfig.QUEUE; | ||
import static com.lalala.alarm.config.RabbitMQConfig.UNDELIVERED_QUEUE; | ||
|
||
import com.lalala.alarm.dto.Email; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.amqp.rabbit.annotation.RabbitListener; | ||
import org.springframework.amqp.rabbit.core.RabbitTemplate; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.messaging.handler.annotation.Header; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.Map; | ||
|
||
@Component | ||
@Slf4j | ||
public class RetryingRabbitListener { | ||
|
||
@Autowired | ||
private RabbitTemplate rabbitTemplate; | ||
|
||
@Value("${rabbitmq.retry.count}") | ||
private Integer retryCount; | ||
|
||
@RabbitListener(queues = QUEUE) | ||
public void primary(Email email, @Header(required = false, name = "x-death") Map<String, ?> xDeath) throws Exception { | ||
log.info("Message read from Queue: " + email); | ||
if (checkRetryCount(xDeath)) { | ||
sendToUndelivered(email); | ||
return; | ||
} | ||
|
||
throw new Exception("Random error"); | ||
} | ||
|
||
|
||
private boolean checkRetryCount(Map<String, ?> xDeath) { | ||
|
||
if (xDeath != null && !xDeath.isEmpty()) { | ||
Long count = (Long) xDeath.get("count"); | ||
return count >= retryCount; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
private void sendToUndelivered(Email email) { | ||
log.warn("maximum retry reached, send message to the undelivered queue, msg: {}", email); | ||
this.rabbitTemplate.convertAndSend(UNDELIVERED_QUEUE, email); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
version: "3.9" | ||
services: | ||
alarm-app: | ||
image: smilegatewannabe/alarm | ||
restart: always | ||
ports: | ||
- 28000:28000 | ||
environment: | ||
SPRING_DATASOURCE_URL: jdbc:mysql://alarm-mysql:3306/user?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&serverTimezone=Asia/Seoul | ||
SPRING_DATASOURCE_USERNAME: root | ||
SPRING_DATASOURCE_PASSWORD: admin | ||
SPRING_DATASOURCE_DRIVER-CLASS-NAME: com.mysql.cj.jdbc.Driver | ||
|
||
SPRING_JPA_PROPERTIES_DIALECT: org.hibernate.dialect.MySQLDialect | ||
|
||
SPRING_MAIL_HOST: smtp.gmail.com | ||
SPRING_MAIL_USERNAME: [email protected] | ||
SPRING_MAIL_PASSWORD: b3^weK*zh47gZxm5 | ||
|
||
SPRING_DATA_REDIS_HOST: alarm-redis | ||
SPRING_DATA_REDIS_PORT: 6379 | ||
|
||
SPRING_KAFKA_BOOTSTRAP-SERVERS: Kafka00Service:9092,Kafka01Service:9092,Kafka02Service:9092 | ||
|
||
EUREKA_CLIENT_SERVICE-URL_DEFAULTZONE: http://discovery-app:8761/eureka | ||
|
||
PASSPORT_ALGORITHM: SHA-256 | ||
PASSPORT_KEY: SECRET_KEY | ||
|
||
MANAGEMENT_ZIPKIN_TRACING_ENDPOINT: http://infra-zipkin:9411/api/v2/spans | ||
|
||
SPRING_RABBITMQ_HOST: alarm-rabbitmq | ||
SPRING_RABBITMQ_PORT: 5672 | ||
depends_on: | ||
- alarm-mysql | ||
- alarm-redis | ||
- alarm-rabbitmq | ||
networks: | ||
- lalala-network | ||
|
||
alarm-mysql: | ||
image: mysql:8.2.0 | ||
restart: always | ||
ports: | ||
- 28100:3306 | ||
environment: | ||
MYSQL_ROOT_PASSWORD: admin | ||
MYSQL_DATABASE: user | ||
TZ: Asia/Seoul | ||
command: | ||
- --character-set-server=utf8mb4 | ||
- --collation-server=utf8mb4_unicode_ci | ||
volumes: | ||
- ./.docker/mysql/:/var/lib/mysql | ||
- ./infra/:/docker-entrypoint-initdb.d | ||
networks: | ||
- lalala-network | ||
|
||
alarm-redis: | ||
image: redis:7.0 | ||
ports: | ||
- 28200:6379 | ||
|
||
alarm-adminer: | ||
image: adminer | ||
restart: always | ||
ports: | ||
- 29900:8080 | ||
|
||
alarm-rabbitmq: | ||
image: rabbitmq:3.10-management | ||
ports: | ||
- "28300:5672" | ||
environment: | ||
RABBITMQ_DEFAULT_USER: admin | ||
RABBITMQ_DEFAULT_PASS: admin | ||
|
||
networks: | ||
lalala-network: | ||
driver: bridge | ||
external: true |
Oops, something went wrong.