use of io.datarouter.aws.sqs.SqsDataTooLargeException in project datarouter by hotpads.
the class SqsPutMultiOp method run.
@Override
protected Void run() {
List<SendMessageBatchRequestEntry> entries = new ArrayList<>(BaseSqsNode.MAX_MESSAGES_PER_BATCH);
List<String> rejectedDatabeans = new ArrayList<>();
int currentPayloadSize = 0;
for (D databean : databeans) {
FieldGeneratorTool.generateAndSetValueForFieldIfNecessary(fieldInfo, databean);
String databeanAsString = codec.toString(databean, fielder);
int encodedDatabeanSize = StringCodec.UTF_8.encode(databeanAsString).length;
if (encodedDatabeanSize > BaseSqsNode.MAX_BYTES_PER_MESSAGE) {
rejectedDatabeans.add(databeanAsString);
continue;
}
if (currentPayloadSize + encodedDatabeanSize > BaseSqsNode.MAX_BYTES_PER_PAYLOAD || entries.size() >= BaseSqsNode.MAX_MESSAGES_PER_BATCH) {
putBatch(entries);
entries = new ArrayList<>();
currentPayloadSize = 0;
}
entries.add(new SendMessageBatchRequestEntry(UUID.randomUUID().toString(), databeanAsString));
currentPayloadSize += encodedDatabeanSize;
}
if (entries.size() > 0) {
putBatch(entries);
}
if (rejectedDatabeans.size() > 0) {
throw new SqsDataTooLargeException(rejectedDatabeans);
}
return null;
}
use of io.datarouter.aws.sqs.SqsDataTooLargeException in project datarouter by hotpads.
the class SqsPutOp method run.
@Override
protected Void run() {
FieldGeneratorTool.generateAndSetValueForFieldIfNecessary(fieldInfo, databean);
String encodedDatabean = codec.toString(databean, fielder);
if (StringCodec.UTF_8.encode(encodedDatabean).length > BaseSqsNode.MAX_BYTES_PER_MESSAGE) {
throw new SqsDataTooLargeException(List.of(encodedDatabean));
}
var request = new SendMessageRequest(queueUrl, encodedDatabean);
try {
sqsClientManager.getAmazonSqs(clientId).sendMessage(request);
} catch (AbortedException e) {
throw new UncheckedInterruptedException("", e);
}
return null;
}
use of io.datarouter.aws.sqs.SqsDataTooLargeException in project datarouter by hotpads.
the class SqsTestHelper method testByteLimitMulti.
public void testByteLimitMulti() {
String longString = makeLongStringWithDatabeanSizeTarget(BaseSqsNode.MAX_BYTES_PER_MESSAGE + 1);
List<TestDatabean> databeans = new ArrayList<>();
databeans.add(new TestDatabean(longString, "", ""));
databeans.add(new TestDatabean(longString, "", ""));
databeans.add(new TestDatabean("demat", "", ""));
try {
dao.putMulti(databeans);
} catch (SqsDataTooLargeException exception) {
Assert.assertEquals(exception.getRejectedDatabeans().size(), 2);
}
}
Aggregations