简体   繁体   中英

Indefinite long polling with Alpakka Java

I am using this library: https://doc.akka.io/docs/alpakka/current/sqs.html for working with SQS.

I am trying to create SQS long polling with it, they provided a snippet for reading messages from SQS:

final CompletionStage<List<Message>> cs =
    SqsSource.create(
            queueUrl,
            SqsSourceSettings.create()
                .withWaitTime(Duration.ofSeconds(1)),
            sqsClient)
        .runWith(Sink.seq(), materializer);

I have used RestartSource from Akka before with Scala, but in Java, I am not able to make this polling indefinite. It stops after a few minutes. What would be a good way to keep the poller alive? Is there any other alternative in Java?

You can achieve this by wrapping your source with RestartSource: https://doc.akka.io/docs/akka/current/stream/stream-error.html#delayed-restarts-with-a-backoff-operator In this, you just have to pass negative value on maxRestart. Documentation was very clear on this, I just couldn't find SQS and this section together.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM