Skip to content

Commit dc2e723

Browse files
authored
[Feat]: AWS SQS 연동 (#142)
SQS 관련 설정 파일 생성 및 구현 application.yml 설정 Related to: #141
1 parent c3f37a7 commit dc2e723

File tree

4 files changed

+86
-0
lines changed

4 files changed

+86
-0
lines changed

build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ dependencies {
5757

5858
// Health Check
5959
implementation 'org.springframework.boot:spring-boot-starter-actuator'
60+
61+
// AWS
62+
implementation platform("io.awspring.cloud:spring-cloud-aws-dependencies:3.0.1")
63+
implementation 'io.awspring.cloud:spring-cloud-aws-starter-sqs'
6064
}
6165

6266
tasks.named('bootBuildImage') {
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package io.sobok.SobokSobok.config;
2+
3+
import io.awspring.cloud.sqs.operations.SqsTemplate;
4+
import org.springframework.beans.factory.annotation.Value;
5+
import org.springframework.context.annotation.Bean;
6+
import org.springframework.context.annotation.Configuration;
7+
import software.amazon.awssdk.auth.credentials.AwsCredentials;
8+
import software.amazon.awssdk.regions.Region;
9+
import software.amazon.awssdk.services.sqs.SqsAsyncClient;
10+
11+
@Configuration
12+
public class SQSConfig {
13+
14+
@Value("${spring.cloud.aws.credentials.access-key}")
15+
private String AWS_ACCESS_KEY;
16+
17+
@Value("${spring.cloud.aws.credentials.secret-key}")
18+
private String AWS_SECRET_KEY;
19+
20+
@Value("${spring.cloud.aws.region.static}")
21+
private String AWS_REGION;
22+
23+
@Bean
24+
public SqsAsyncClient sqsAsyncClient() {
25+
return SqsAsyncClient.builder()
26+
.credentialsProvider(() -> new AwsCredentials() {
27+
@Override
28+
public String accessKeyId() {
29+
return AWS_ACCESS_KEY;
30+
}
31+
32+
@Override
33+
public String secretAccessKey() {
34+
return AWS_SECRET_KEY;
35+
}
36+
})
37+
.region(Region.of(AWS_REGION))
38+
.build();
39+
}
40+
41+
@Bean
42+
public SqsTemplate sqsTemplate() {
43+
return SqsTemplate.newTemplate(sqsAsyncClient());
44+
}
45+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package io.sobok.SobokSobok.external.aws.sqs;
2+
3+
import io.awspring.cloud.sqs.operations.SendResult;
4+
import io.awspring.cloud.sqs.operations.SqsTemplate;
5+
import org.springframework.beans.factory.annotation.Value;
6+
import org.springframework.stereotype.Component;
7+
import software.amazon.awssdk.services.sqs.SqsAsyncClient;
8+
9+
@Component
10+
public class SQSMessageSender {
11+
12+
private final SqsTemplate queueMessagingTemplate;
13+
14+
@Value("${spring.cloud.aws.sqs.name}")
15+
private String QUEUE_NAME;
16+
17+
public SQSMessageSender(SqsAsyncClient sqsAsyncClient) {
18+
this.queueMessagingTemplate = SqsTemplate.newTemplate(sqsAsyncClient);
19+
}
20+
21+
public SendResult<SQSPushNotificationRequest> sendMessage(SQSPushNotificationRequest request) {
22+
return queueMessagingTemplate.send(to -> to
23+
.queue(QUEUE_NAME)
24+
.payload(request));
25+
}
26+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package io.sobok.SobokSobok.external.aws.sqs;
2+
3+
public record SQSPushNotificationRequest(
4+
5+
String deviceToken,
6+
7+
String title,
8+
9+
String content
10+
) {
11+
}

0 commit comments

Comments
 (0)