Skip to content

Commit

Permalink
[Feat]: AWS SQS 연동 (#142)
Browse files Browse the repository at this point in the history
SQS 관련 설정 파일 생성 및 구현
application.yml 설정

Related to: #141
  • Loading branch information
dev-Crayon authored Jul 1, 2024
1 parent c3f37a7 commit dc2e723
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 0 deletions.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ dependencies {

// Health Check
implementation 'org.springframework.boot:spring-boot-starter-actuator'

// AWS
implementation platform("io.awspring.cloud:spring-cloud-aws-dependencies:3.0.1")
implementation 'io.awspring.cloud:spring-cloud-aws-starter-sqs'
}

tasks.named('bootBuildImage') {
Expand Down
45 changes: 45 additions & 0 deletions src/main/java/io/sobok/SobokSobok/config/SQSConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package io.sobok.SobokSobok.config;

import io.awspring.cloud.sqs.operations.SqsTemplate;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import software.amazon.awssdk.auth.credentials.AwsCredentials;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.sqs.SqsAsyncClient;

@Configuration
public class SQSConfig {

@Value("${spring.cloud.aws.credentials.access-key}")
private String AWS_ACCESS_KEY;

@Value("${spring.cloud.aws.credentials.secret-key}")
private String AWS_SECRET_KEY;

@Value("${spring.cloud.aws.region.static}")
private String AWS_REGION;

@Bean
public SqsAsyncClient sqsAsyncClient() {
return SqsAsyncClient.builder()
.credentialsProvider(() -> new AwsCredentials() {
@Override
public String accessKeyId() {
return AWS_ACCESS_KEY;
}

@Override
public String secretAccessKey() {
return AWS_SECRET_KEY;
}
})
.region(Region.of(AWS_REGION))
.build();
}

@Bean
public SqsTemplate sqsTemplate() {
return SqsTemplate.newTemplate(sqsAsyncClient());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package io.sobok.SobokSobok.external.aws.sqs;

import io.awspring.cloud.sqs.operations.SendResult;
import io.awspring.cloud.sqs.operations.SqsTemplate;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import software.amazon.awssdk.services.sqs.SqsAsyncClient;

@Component
public class SQSMessageSender {

private final SqsTemplate queueMessagingTemplate;

@Value("${spring.cloud.aws.sqs.name}")
private String QUEUE_NAME;

public SQSMessageSender(SqsAsyncClient sqsAsyncClient) {
this.queueMessagingTemplate = SqsTemplate.newTemplate(sqsAsyncClient);
}

public SendResult<SQSPushNotificationRequest> sendMessage(SQSPushNotificationRequest request) {
return queueMessagingTemplate.send(to -> to
.queue(QUEUE_NAME)
.payload(request));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.sobok.SobokSobok.external.aws.sqs;

public record SQSPushNotificationRequest(

String deviceToken,

String title,

String content
) {
}

0 comments on commit dc2e723

Please sign in to comment.