1
votes

I am preparing demo programme which listen from the Amazon SQS.Below is my code.

xml config

<aws-messaging:annotation-driven-queue-listener  amazon-sqs="sqsClient" max-number-of-messages="10" wait-time-out="20" visibility-timeout="100" />

UserServiceListenr.java

@Configuration
@EnableSqs
@Component
public class UserServiceListenr {
    @SqsListener(value = "CMR", deletionPolicy = SqsMessageDeletionPolicy.ON_SUCCESS)
    public void myQueueListener(Message message) throws Exception{
        try {
            System.out.println("Message Listen start");
            System.out.println("Message part "+message);
        }catch(Exception e){
            System.out.println(" message Exception " + e);
        }
    }
}

I have put 2 messages on SQS queue.when I try to fetch messages using this demo programme Messages shown Messages_in_flight column in my AWS console.but messages not reach to my sqsListener method and after few minutes messages shown to Messages_available column in AWS console.

Below is the Exception I got when run the programme.

QueueMessageHandler:294 - 1 message handler methods found on class com.sophos.cmr.demo.UserServiceListenr: {public void com.sophos.cmr.demo.UserServiceListenr.myQueueListener(java.lang.String) throws java.lang.Exception=org.springframework.cloud.aws.messaging.listener.QueueMessageHandler$MappingInformation@5f0e9815}

so what's going wrong if any clue?

2

2 Answers

0
votes

When you see that message move to column Messages_in_flight - it means that the message was picked up by a consumer but the acknowledgment about success handling, for this specific message, still didn`t receive.

So reason could be the next: 1) Error/Exception appears during the handling message from SQS 2) Spring can`t find appropriate ArgumentResolver to convert income message from SQS to your bean. I see you are using your custom bean - 'Message'

You can look through documentation, section 5.2.5

0
votes

I had a similar issue and was able to solve it. The docs aren't clear on this matter. I am adding it here in case someone sees this later on.

First, when you insert an item into queue, you need to set some additional message properties so Spring knows to marshall it into your bean. If you set Name: contentType Type: String Value: application/json in the GUI when adding a message to queue, then spring will try to marshall it with Jackson.

Second, I wasn't able to get @SqsListener to work with a non String argument unless it was inside a class annotated with @Controller. For non-controller classes, I had to add a second method argument (@Header("SenderId") String senderId worked for me) and then it routed correctly