mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 22:11:36 -05:00
fix(pipes): invoke non-Lambda targets per-record instead of batch envelope (#590)
This commit is contained in:
1 parent
e5848487aa
commit
02facf40f6
2 files changed
+59
-18
No files matched your search
@@ -19,6 +19,7 @@ import jakarta.inject.Inject;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -171,17 +172,37 @@ public class PipesPoller {
|
||||
return;
|
||||
}
|
||||
|
||||
// Attempt delivery; only delete matching messages after successful delivery or DLQ routing
|
||||
String eventJson = wrapRecords(filtered);
|
||||
boolean delivered = invokeWithDlq(pipe, eventJson, region);
|
||||
if (delivered) {
|
||||
if (isLambdaTarget(pipe)) {
|
||||
String eventJson = wrapRecords(filtered);
|
||||
boolean delivered = invokeWithDlq(pipe, eventJson, region);
|
||||
if (delivered) {
|
||||
for (Message msg : messages) {
|
||||
if (matchedMessageIds.contains(msg.getMessageId())) {
|
||||
try {
|
||||
sqsService.deleteMessage(queueUrl, msg.getReceiptHandle(), region);
|
||||
} catch (Exception e) {
|
||||
LOG.warnv("Pipe {0}: failed to delete SQS message {1}: {2}",
|
||||
pipe.getName(), msg.getMessageId(), e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Map<String, Message> messagesById = new HashMap<>();
|
||||
for (Message msg : messages) {
|
||||
if (matchedMessageIds.contains(msg.getMessageId())) {
|
||||
try {
|
||||
sqsService.deleteMessage(queueUrl, msg.getReceiptHandle(), region);
|
||||
} catch (Exception e) {
|
||||
LOG.warnv("Pipe {0}: failed to delete SQS message {1}: {2}",
|
||||
pipe.getName(), msg.getMessageId(), e.getMessage());
|
||||
messagesById.put(msg.getMessageId(), msg);
|
||||
}
|
||||
for (JsonNode record : filtered) {
|
||||
String messageId = record.get("messageId").asText();
|
||||
if (invokeWithDlq(pipe, record.toString(), region)) {
|
||||
Message msg = messagesById.get(messageId);
|
||||
if (msg != null) {
|
||||
try {
|
||||
sqsService.deleteMessage(queueUrl, msg.getReceiptHandle(), region);
|
||||
} catch (Exception e) {
|
||||
LOG.warnv("Pipe {0}: failed to delete SQS message {1}: {2}",
|
||||
pipe.getName(), msg.getMessageId(), e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -218,10 +239,10 @@ public class PipesPoller {
|
||||
if (filtered.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
String eventJson = wrapRecords(filtered);
|
||||
if (!invokeWithDlq(pipe, eventJson, region)) {
|
||||
int failed = deliverRecords(pipe, filtered, region);
|
||||
if (failed > 0) {
|
||||
LOG.warnv("Pipe {0}: {1} Kinesis record(s) dropped — delivery and DLQ both failed",
|
||||
pipe.getName(), filtered.size());
|
||||
pipe.getName(), failed);
|
||||
}
|
||||
} catch (AwsException e) {
|
||||
if ("ExpiredIteratorException".equals(e.getErrorCode())) {
|
||||
@@ -269,10 +290,10 @@ public class PipesPoller {
|
||||
if (filtered.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
String eventJson = wrapRecords(filtered);
|
||||
if (!invokeWithDlq(pipe, eventJson, region)) {
|
||||
int failed = deliverRecords(pipe, filtered, region);
|
||||
if (failed > 0) {
|
||||
LOG.warnv("Pipe {0}: {1} DynamoDB Stream record(s) dropped — delivery and DLQ both failed",
|
||||
pipe.getName(), filtered.size());
|
||||
pipe.getName(), failed);
|
||||
}
|
||||
} catch (AwsException e) {
|
||||
if ("ExpiredIteratorException".equals(e.getErrorCode()) ||
|
||||
@@ -295,6 +316,19 @@ public class PipesPoller {
|
||||
|
||||
// ──────────────────────────── Invocation & DLQ ────────────────────────────
|
||||
|
||||
private int deliverRecords(Pipe pipe, List<JsonNode> records, String region) {
|
||||
if (isLambdaTarget(pipe)) {
|
||||
return invokeWithDlq(pipe, wrapRecords(records), region) ? 0 : records.size();
|
||||
}
|
||||
int failed = 0;
|
||||
for (JsonNode record : records) {
|
||||
if (!invokeWithDlq(pipe, record.toString(), region)) {
|
||||
failed++;
|
||||
}
|
||||
}
|
||||
return failed;
|
||||
}
|
||||
|
||||
private boolean invokeWithDlq(Pipe pipe, String eventJson, String region) {
|
||||
try {
|
||||
targetInvoker.invoke(pipe, eventJson, region);
|
||||
@@ -414,6 +448,11 @@ public class PipesPoller {
|
||||
|
||||
// ──────────────────────────── Utilities ────────────────────────────
|
||||
|
||||
private static boolean isLambdaTarget(Pipe pipe) {
|
||||
String targetArn = pipe.getTarget();
|
||||
return targetArn.contains(":lambda:") || targetArn.contains(":function:");
|
||||
}
|
||||
|
||||
private static String pipeKey(Pipe pipe) {
|
||||
return pipe.getArn();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user