Skip to content

Commit

Permalink
Ab2d-6340/event client exception (#419)
Browse files Browse the repository at this point in the history
* wip

* Added logs and SqsMessageListenerContainerFactory

* Added logs and SqsMessageListenerContainerFactory

* Added logs and SqsMessageListenerContainerFactory
  • Loading branch information
smirnovaae authored Jan 10, 2025
1 parent 8b04dab commit b2917cc
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
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: {}", queueUrl);

} 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

0 comments on commit b2917cc

Please sign in to comment.