aws / aws-sdk-java-v2

The official AWS SDK for Java - Version 2
Apache License 2.0
2.2k stars 847 forks source link

Polling Event Consumer (SQS, DynamoDB Streams) #38

Open millems opened 7 years ago

millems commented 7 years ago

Customers are currently required to manually poll an SQS queue for data. An event-driven SQS consumer should be provided that handles this polling so that customers can just focus on processing messages.

zlangbert commented 6 years ago

Is this a planned feature? Would be awesome to see!

divY42 commented 5 years ago

Just to let you know: This is possible over lambdas (so might not be a usable case for everyone). You can specify a lambda to be triggered whenever a message is sent to a specific queue. This was added in June 2018.

https://aws.amazon.com/de/blogs/aws/aws-lambda-adds-amazon-simple-queue-service-to-supported-event-sources/

import com.amazonaws.services.lambda.runtime.Context; import com.amazonaws.services.lambda.runtime.RequestHandler; import com.amazonaws.services.lambda.runtime.events.SQSEvent; import com.amazonaws.services.lambda.runtime.events.SQSEvent.SQSMessage;

public class LambdaHandler implements RequestHandler<SQSEvent, String> {

private static Logger log = LogManager.getLogger(LambdaHandler.class);

@Override public String handleRequest(SQSEvent event, Context context) {

for (SQSMessage message : event.getRecords()) {
  log.debug("received the following message: {}", message.getBody());
}

return "{}";

} }