spring-cloud-aws icon indicating copy to clipboard operation
spring-cloud-aws copied to clipboard

spring boot native image is not able to read message from AWS SQS

Open pulsar-gupta opened this issue 1 year ago • 2 comments

Type: Bug

Component: SQS

Describe the bug

I have an application and it reads messages from sqs when run locally but as soon as I deploy it's native image on EKS nothing happens and messages are queued on SQS. It looks as is my native image is not reading messages from SQS. No logs are printed and no exception.

Here is my code:

@Configuration public class ReaderConfiguration {

@Bean
public SqsClient sqsClient() {
	try {		
		AwsBasicCredentials credentials = AwsBasicCredentials.create("access-key", "secret");
		return SqsClient.builder().region(Region.of("eu-central-1")).credentialsProvider(() -> credentials).build();
	} catch (Exception e) {
		e.printStackTrace();
		throw new AwsAuthenticationError("Aws Authentication Error");
	}
}

} @Component public class SQSListner {

private SqsClient sqsClient = null;

@Autowired
public SQSListner(SqsClient sqsClient) {
	this.sqsClient = sqsClient;
}

@SqsListener("notification")
public void recieveMessage(Message msg) {
	System.out.println("Received Message" + msg.body());
	// processMsg();
}

} <groupId>io.awspring.cloud</groupId> <artifactId>spring-cloud-aws-starter-sqs</artifactId> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> 3.0.0 <relativePath /> image is build using mvn -Pnative spring-boot:build-image

pulsar-gupta avatar Jan 15 '24 09:01 pulsar-gupta

Hey @pulsar-gupta , we have open PR for this it is known issue.

MatejNedic avatar Jan 30 '24 20:01 MatejNedic

with some changes I was able to resolve the issue first step was to upgrade the spring boot and spring cloud version

  1. io.awspring.cloud - spring-cloud-aws-dependencies - 3.1.o
  2. software.amazon.awssdk - bom - 2.20.45
  3. spring-boot - 3.2.1

second step was to register hints

  • MyListener class is where I have @SqsListener method 'recieveMessage' to receive and process the messages from queue

    @Override public void registerHints(RuntimeHints hints, ClassLoader classLoader) { // Register method for reflection Method sqsReceiveMethod = ReflectionUtils.findMethod(MyListener.class, "recieveMessage", Message.class); hints.reflection().registerMethod(sqsReceiveMethod, ExecutableMode.INVOKE); hints.resources().registerPattern("io/awspring/cloud/core/SpringCloudClientConfiguration.properties"); }

and created image mvn -Pnative spring-boot:build-image

Now works absolutely fine

pulsar-gupta avatar Jan 31 '24 05:01 pulsar-gupta