I am consuming the events that occurred in the s3 bucket using the SQS and fetching the s3 object using the keys, I am using the @SqsListener to listen to the events. As per the documentation, I may use the custom objects as shown below, when I use the S3EventNotification to get the records and fetch s3 bucket keys I am getting it as null while if I use String instead of S3EventNotification class I am able to get the JSON in string format. I think I should get the record using the S3EventNotification.getRecords() method and not convert the string to class. Is it the excepted behavior or is it the bug?
QueueListener.java
@Component
@Slf4j
public class QueueListener {
// log -> message null
@SqsListener(value = "${cloud.aws.end-point.uri}", deletionPolicy = SqsMessageDeletionPolicy.ON_SUCCESS)
public void onS3UploadEvent(S3EventNotification s3EventNotification) throws IOException {
log.info("message: {}", s3EventNotification.getRecords());
}
// log -> message as json string with records and other details
@SqsListener(value = "${cloud.aws.end-point.uri}", deletionPolicy = SqsMessageDeletionPolicy.ON_SUCCESS)
public void onS3UploadEvent(String message) throws IOException {
log.info("message: {}", message);
}
}
MessagingConfig.java
import java.util.Collections;
import org.springframework.cloud.aws.messaging.config.QueueMessageHandlerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.converter.MappingJackson2MessageConverter;
import org.springframework.messaging.handler.annotation.support.PayloadMethodArgumentResolver;
@Configuration
public class MessagingConfig {
@Bean
public QueueMessageHandlerFactory queueMessageHandlerFactory() {
QueueMessageHandlerFactory factory = new QueueMessageHandlerFactory();
MappingJackson2MessageConverter messageConverter = new MappingJackson2MessageConverter();
messageConverter.setStrictContentTypeMatch(false);
factory.setArgumentResolvers(Collections.singletonList(new PayloadMethodArgumentResolver(messageConverter)));
return factory;
}
}
I am consuming the events that occurred in the s3 bucket using the SQS and fetching the s3 object using the keys, I am using the @SqsListener to listen to the events. As per the documentation, I may use the custom objects as shown below, when I use the
S3EventNotification
to get the records and fetch s3 bucket keys I am getting it as null while if I use String instead of S3EventNotification class I am able to get the JSON in string format. I think I should get the record using the S3EventNotification.getRecords() method and not convert the string to class. Is it the excepted behavior or is it the bug?QueueListener.java
MessagingConfig.java
pom.xml
application.properties
AWS Configurations
Java 11