Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ab2d-6340/event client exception #419

Merged
merged 7 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
import com.fasterxml.jackson.databind.jsontype.impl.LaissezFaireSubTypeValidator;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import gov.cms.ab2d.eventclient.config.Ab2dEnvironment;
import io.awspring.cloud.sqs.config.SqsBootstrapConfiguration;
import io.awspring.cloud.sqs.config.SqsMessageListenerContainerFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Primary;
import org.springframework.messaging.converter.MappingJackson2MessageConverter;
import org.springframework.messaging.converter.MessageConverter;
Expand All @@ -24,6 +27,7 @@

import java.net.URI;

@Import(SqsBootstrapConfiguration.class)
@Configuration
@Slf4j
public class SQSConfig {
Expand All @@ -49,6 +53,14 @@ public SQSConfig(@Value("${cloud.aws.region.static}") String region,
System.setProperty("sqs.queue-name", sqsQueueName);
}

@Bean
public SqsMessageListenerContainerFactory<Object> defaultSqsListenerContainerFactory() {
return SqsMessageListenerContainerFactory
.builder()
.sqsAsyncClient(amazonSQSAsync())
.build();
}

@Primary
@Bean
public SqsAsyncClient amazonSQSAsync() {
Expand All @@ -60,6 +72,7 @@ public SqsAsyncClient amazonSQSAsync() {
.region(Region.US_EAST_1)
.build());
}
log.info("Creating SqsAsyncClient");
return SqsAsyncClient.builder()
.credentialsProvider(DefaultCredentialsProvider.builder().build())
.region(Region.US_EAST_1)
Expand Down Expand Up @@ -99,7 +112,7 @@ public SqsAsyncClient createQueue(SqsAsyncClient sqsClient) {
.build();

sqsClient.createQueue(createQueueRequest);
log.info("Queue created");
log.info("Queue created: " + sqsQueueName);
} catch (SqsException e) {
log.error(e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ public SQSEventClient(SqsAsyncClient amazonSQS, ObjectMapper mapper, String queu

@Override
public void sendLogs(LoggableEvent requestEvent) {
log.info("Send logs to queue: {}", queueName);
GeneralSQSMessage sqsMessage = new GeneralSQSMessage(requestEvent);
sendMessage(sqsMessage);
}

@Override
public void alert(String message, List<Ab2dEnvironment> environments) {
log.info("Send alert to queue: {}", queueName);
AlertSQSMessage sqsMessage = new AlertSQSMessage(message, environments);
sendMessage(sqsMessage);
}
Expand Down Expand Up @@ -116,6 +118,7 @@ public void sendMessage(SQSMessages message) {
.build();

amazonSQS.sendMessage(sendMessageRequest);
log.info("Sent message {} to queue: {}", sendMessageRequest.messageBody(), queueUrl);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what is contained inside messageBody, but if it's sensitive we shouldn't log it. Otherwise looks good.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. Removed sendMessageRequest from logs


} catch (JsonProcessingException | UnsupportedOperationException | SqsException e) {
log.info(e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ ext {
bfdVersion='3.2.0'
aggregatorVersion='2.0.0'
filtersVersion='2.1.0'
eventClientVersion='3.2.0'
eventClientVersion='3.2.1'
propertiesClientVersion='2.0.0'
contractClientVersion='2.0.0'
snsClientVersion='1.0.0'
Expand Down