This repository was archived by the owner on Jan 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 367
This repository was archived by the owner on Jan 19, 2022. It is now read-only.
s3EventNotification.getRecords() returns null even when the record is present #804
Copy link
Copy link
Open
Labels
status: waiting-for-triageAn issue we've not yet triagedAn issue we've not yet triaged
Description
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;
}
}
pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.6</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<spring.cloud-version>2020.0.5</spring.cloud-version>
<spring-cloud-starter-aws.version>2.2.6.RELEASE</spring-cloud-starter-aws.version>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-aws-messaging</artifactId>
<version>${spring-cloud-starter-aws.version}</version>
</dependency>
application.properties
AWS Configurations
cloud.aws.credentials.use-default-aws-credentials-chain = true
cloud.aws.end-point.uri = https://sqs.eu-west-2.amazonaws.com/<id>/<name>
Java 11
Metadata
Metadata
Assignees
Labels
status: waiting-for-triageAn issue we've not yet triagedAn issue we've not yet triaged