问题描述:

maybe someone has an idea to my following problem:

I am currently on a project, where i want to use the AWS SQS with Spring Cloud integration. For the receiver part i want to provide a API, where a user can register a "message handler" on a queue, which is an interface and will contain the user's business logic, e.g.

MyAwsSqsReceiver receiver = new MyAwsSqsReceiver();

receiver.register("a-queue-name", new MessageHandler(){

@Override

public void handle(String message){

//... business logic for the received message

}

});

I found examples, e.g.

https://codemason.me/2016/03/12/amazon-aws-sqs-with-spring-cloud/

and read the docu

http://cloud.spring.io/spring-cloud-aws/spring-cloud-aws.html#_sqs_support

But the only thing i found there to "connect" a functionality for processing a incoming message is a annotation on a method, e.g. @SqsListener or @MessageMapping.

These annotations are fixed to a certain queue-name, though. So now i am at a loss, how to dynamically "connect" my provided "MessageHandler" (from my API) to the incoming message for the specified queuename.

In the Config the example there is a SimpleMessageListenerContainer, which gets a QueueMessageHandler set, but this QueueMessageHandler does not seem

to be the right place to set my handler or to override its methods and provide my own subclass of QueueMessageHandler.

I already did something like this with the Spring Amqp integration and RabbitMq and thought, that it would be also similar here with AWS SQS.

Does anyone have an idea, how to accomplish this?

thx + bye,

Ximon

EDIT:

I found, that Spring JMS could actually do that, e.g. www.javacodegeeks.com/2016/02/aws-sqs-spring-jms-integration.html. Does anybody know, what consequences using JMS protocol has here, good or bad?

网友答案:

When we do Spring and SQS we use the spring-cloud-starter-aws-messaging.

Then just create a Listener class

@Component
public class MyListener {

@SQSListener(value="myqueue")
public void listen(MyMessageType message) {
//process the message
}
}
相关阅读:
Top