There is a method to explicitly call a flash, but it is not available, and in fact, I could not find a call to this method in amazon code. Something seems to be missing.
When you call shutdown on an asynchronous client, it executes the following code:
public void shutdown() { for( QueueBuffer buffer : buffers.values() ) { buffer.shutdown(); } realSQS.shutdown(); }
And QueueBuffer # shutdown () looks like this:
public void shutdown() {
So it looks like they intentionally do not call sendBuffer.shutdown (), which is a method that flushes every message in a buffer that has not yet been sent.
Have you discovered a case where you are shutting down SQS Client and have lost messages? They seem to know about this, and in this case this should not happen, but if you want to be sure that you can call this method with a reflection that it is really nasty, but it will satisfy your needs.
AmazonSQSBufferedAsyncClient asyncSqsClient = <your initialization code of the client>; Field buffersField = ReflectionUtils.findField(AmazonSQSBufferedAsyncClient.class, "buffers"); ReflectionUtils.makeAccessible(buffersField); LinkedHashMap<String, Object> buffers = (LinkedHashMap<String, Object>) ReflectionUtils.getField(buffersField, asyncSqsClient); for (Object buffer : buffers.values()) { Class<?> clazz = Class.forName("com.amazonaws.services.sqs.buffered.QueueBuffer"); SendQueueBuffer sendQueueBuffer = (SendQueueBuffer) ReflectionUtils.getField(ReflectionUtils.findField(clazz, "sendBuffer"), buffer); sendQueueBuffer.flush();//finally }
Something like this should work, I think. Let me know!
source share