Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
pulsar-gupta opened this issue Jan 15, 2024 · 2 comments
Open

Comments

@pulsar-gupta
Copy link

pulsar-gupta commented Jan 15, 2024

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();
}

}

io.awspring.cloud
spring-cloud-aws-starter-sqs


org.springframework.boot
spring-boot-starter-parent
3.0.0


image is build using mvn -Pnative spring-boot:build-image

@MatejNedic
Copy link
Member

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

@pulsar-gupta
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants