Search in sources :

Example 1 with SqsDataTooLargeException

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;
}
Also used : UUID(java.util.UUID) SqsDataTooLargeException(io.datarouter.aws.sqs.SqsDataTooLargeException) ArrayList(java.util.ArrayList) SendMessageBatchRequestEntry(com.amazonaws.services.sqs.model.SendMessageBatchRequestEntry)

Example 2 with SqsDataTooLargeException

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;
}
Also used : AbortedException(com.amazonaws.AbortedException) SqsDataTooLargeException(io.datarouter.aws.sqs.SqsDataTooLargeException) UncheckedInterruptedException(io.datarouter.util.concurrent.UncheckedInterruptedException) SendMessageRequest(com.amazonaws.services.sqs.model.SendMessageRequest)

Example 3 with SqsDataTooLargeException

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);
    }
}
Also used : TestDatabean(io.datarouter.storage.test.TestDatabean) SqsDataTooLargeException(io.datarouter.aws.sqs.SqsDataTooLargeException) ArrayList(java.util.ArrayList)

Aggregations

SqsDataTooLargeException (io.datarouter.aws.sqs.SqsDataTooLargeException)3 ArrayList (java.util.ArrayList)2 AbortedException (com.amazonaws.AbortedException)1 SendMessageBatchRequestEntry (com.amazonaws.services.sqs.model.SendMessageBatchRequestEntry)1 SendMessageRequest (com.amazonaws.services.sqs.model.SendMessageRequest)1 TestDatabean (io.datarouter.storage.test.TestDatabean)1 UncheckedInterruptedException (io.datarouter.util.concurrent.UncheckedInterruptedException)1 UUID (java.util.UUID)1