private MessageId sendSerializableInternal(Serializable object, Optional<Duration> duration) {
String encodedMessage;
try {
encodedMessage = Util.serializeToBase64(object);
} catch (IOException e) {
throw new SQSRuntimeException("Could not serialize message.", e);
}
checkState(encodedMessage.length() <= 64 * 1024);
LOG.debug("Serialized Message: " + encodedMessage);
SendMessageRequest request = new SendMessageRequest(url, encodedMessage);
if (duration.isPresent()) {
request.withDelaySeconds((int) duration.get().getStandardSeconds());
}
for (int i = 0; i < DELIVERY_RETRY_LIMIT; ++i) {
try {
/* No verification of message checksum is done at this point. It might get added in the future, though. */
return new MessageId(sqsClient.sendMessage(request).getMessageId());
} catch (AmazonServiceException e) {
LOG.warn(format("Could not sent message to SQS queue: %s. Retrying.", url), e);
try {
Thread.sleep(DELIVERY_RETRY_SLEEP_TIME_IN_MILLIS);
} catch (InterruptedException e1) {
// Ignore
}
}
}
throw new SQSRuntimeException("Exceeded redelivery value: " + DELIVERY_RETRY_LIMIT + "; message not sent!");
}