Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

s3EventNotification.getRecords() returns null even when the record is present #804

Open
romil-patel-integrella opened this issue Jan 11, 2022 · 0 comments
Labels
status: waiting-for-triage An issue we've not yet triaged

Comments

@romil-patel-integrella
Copy link

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

@github-actions github-actions bot added the status: waiting-for-triage An issue we've not yet triaged label Jan 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: waiting-for-triage An issue we've not yet triaged
Development

No branches or pull requests

1 participant