Skip to content

Commit

Permalink
[hotfix] publishToSns 메서드 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
0112leesy committed Nov 23, 2023
1 parent 05e694c commit 9df6a3c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
import java.util.Map;
import kr.mybrary.userservice.global.config.AwsSnsConfig;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import software.amazon.awssdk.services.sns.SnsClient;
import software.amazon.awssdk.services.sns.model.PublishRequest;

@Service
@Slf4j
@RequiredArgsConstructor
public class SnsEventPublisher {

Expand All @@ -19,18 +21,22 @@ public class SnsEventPublisher {

public void publishToSns(Map<String, Object> messageData, SnsTopic topic) {

String message;
try {
PublishRequest publishRequest = PublishRequest.builder()
.topicArn(awsConfig.getTopicArn() + topic.getTopicName())
.subject(MESSAGE_SUBJECT)
.message(objectMapper.writeValueAsString(messageData))
.build();

SnsClient snsClient = awsConfig.getSnsClient();
snsClient.publish(publishRequest);

message = objectMapper.writeValueAsString(messageData);
} catch (JsonProcessingException e) {
throw new RuntimeException("Failed to convert message data to JSON", e);
}

String topicArn = awsConfig.getTopicArn() + topic.getTopicName();
PublishRequest publishRequest = PublishRequest.builder()
.topicArn(topicArn)
.subject(MESSAGE_SUBJECT)
.message(message)
.build();

SnsClient snsClient = awsConfig.getSnsClient();
snsClient.publish(publishRequest);
log.info("Publishing message to SNS MESSAGE: {}", message);
}
}
2 changes: 1 addition & 1 deletion user-service/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ eureka:
fetch-registry: true
service-url:
defaultZone: http://127.0.0.1:8761/eureka
enabled: false

management:
endpoints:
Expand Down Expand Up @@ -136,7 +137,6 @@ spring:
logging:
level:
root: info
org.hibernate.SQL: debug

jwt:
secretKey: ${JWT_SECRET_KEY}
Expand Down

0 comments on commit 9df6a3c

Please sign in to comment.