Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I force AmazonSQSBufferedAsyncClient to flush messages?

I'm using the AWS SDK for Java and I'm using the buffering async sqs client to batch requests so that I reduce costs.

When my application shuts down, I want to ensure that no messages are waiting in the buffer, but there's no .flush() method I can see on the client.

Does AmazonSQSBufferedAsyncClient.shutdown() flush my messages when called? I looked at the source code and it's unclear. The method calls shutdown() on each QueueBuffer that it has, but inside QueueBuffer.shutdown() it says

public void shutdown() {
  //send buffer does not require shutdown, only
  //shut down receive buffer
  receiveBuffer.shutdown();
}

Further, the documentation for .shutdown() says:

Shuts down this client object, releasing any resources that might be held open. This is an optional method, and callers are not expected to call it, but can if they want to explicitly release any open resources. Once a client has been shutdown, it should not be used to make any more requests.

For this application, I need to ensure no messages get lost while being buffered. Do I need to handle this manually using the normal AmazonSQSClient instead of the buffering/async one?

like image 802
Daenyth Avatar asked Jun 17 '14 17:06

Daenyth


1 Answers

With 1.11.37 version of the SDK, there is a configuration parameter just for this purpose in QueueBufferConfig.

AmazonSQSBufferedAsyncClient bufClient =
    new AmazonSQSBufferedAsyncClient(
        realAsyncClient,
        new QueueBufferConfig( )
            .withFlushOnShutdown(true)
    );
like image 110
Alexander Pogrebnyak Avatar answered Nov 07 '22 21:11

Alexander Pogrebnyak