@ Override public void put ( Set < Task > tasks ) { String msgBody = null ; SendMessageBatchRequestEntry msgEntry = null ; Set < SendMessageBatchRequestEntry > msgEntries = new HashSet <> ( ) ; for ( Task task : tasks ) { msgBody = unmarshallTask ( task ) ; msgEntry = new SendMessageBatchRequestEntry ( ) . withMessageBody ( msgBody ) . withId ( msgEntries . size ( ) + "" ) ; // must set unique ID for each msg in the batch request msgEntries . add ( msgEntry ) ; // Can only send batch of max 10 messages in a SQS queue request if ( msgEntries . size ( ) == 10 ) { this . sendBatchMessages ( msgEntries ) ; msgEntries . clear ( ) ; // clear the already sent messages } } // After for loop check to see if there are msgs in msgEntries that // haven't been sent yet because the size never reached 10. if ( ! msgEntries . isEmpty ( ) ) { this . sendBatchMessages ( msgEntries ) ; } }
Puts multiple tasks on the queue using batch puts . The tasks argument can contain more than 10 Tasks in that case there will be multiple SQS batch send requests made each containing up to 10 messages .