-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SQS 관련 설정 파일 생성 및 구현 application.yml 설정 Related to: #141
- Loading branch information
1 parent
c3f37a7
commit dc2e723
Showing
4 changed files
with
86 additions
and
0 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 |
---|---|---|
@@ -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()); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/io/sobok/SobokSobok/external/aws/sqs/SQSMessageSender.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,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)); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/io/sobok/SobokSobok/external/aws/sqs/SQSPushNotificationRequest.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,11 @@ | ||
package io.sobok.SobokSobok.external.aws.sqs; | ||
|
||
public record SQSPushNotificationRequest( | ||
|
||
String deviceToken, | ||
|
||
String title, | ||
|
||
String content | ||
) { | ||
} |