mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
fix: honor queue-level DelaySeconds for standard SQS queues (#1567)
This commit is contained in:
1 parent
c3980ebab0
commit
0626cd94d6
4 files changed
+76
-19
No files matched your search
@@ -195,7 +195,8 @@ public class SqsJsonHandler {
|
||||
private Response handleSendMessage(JsonNode request, String region) {
|
||||
String queueUrl = request.path("QueueUrl").asText(null);
|
||||
String messageBody = request.path("MessageBody").asText(null);
|
||||
int delaySeconds = request.path("DelaySeconds").asInt(0);
|
||||
JsonNode delayNode = request.path("DelaySeconds");
|
||||
Integer delaySeconds = parseOptionalInteger(delayNode, "DelaySeconds");
|
||||
String messageGroupId = request.path("MessageGroupId").asText(null);
|
||||
String messageDeduplicationId = request.path("MessageDeduplicationId").asText(null);
|
||||
|
||||
@@ -347,7 +348,7 @@ public class SqsJsonHandler {
|
||||
ArrayNode successful = objectMapper.createArrayNode();
|
||||
ArrayNode failed = objectMapper.createArrayNode();
|
||||
|
||||
record ParsedEntry(String id, String body, int delay, String groupId, String dedupId,
|
||||
record ParsedEntry(String id, String body, Integer delay, String groupId, String dedupId,
|
||||
Map<String, MessageAttributeValue> attributes, String awsTraceHeader) {}
|
||||
|
||||
List<ParsedEntry> parsedEntries = new ArrayList<>();
|
||||
@@ -356,7 +357,8 @@ public class SqsJsonHandler {
|
||||
for (JsonNode entry : entries) {
|
||||
String id = entry.path("Id").asText();
|
||||
String messageBody = entry.path("MessageBody").asText(null);
|
||||
int delaySeconds = entry.path("DelaySeconds").asInt(0);
|
||||
JsonNode entryDelayNode = entry.path("DelaySeconds");
|
||||
Integer delaySeconds = parseOptionalInteger(entryDelayNode, "DelaySeconds");
|
||||
String messageGroupId = entry.path("MessageGroupId").asText(null);
|
||||
String messageDeduplicationId = entry.path("MessageDeduplicationId").asText(null);
|
||||
|
||||
@@ -583,4 +585,15 @@ public class SqsJsonHandler {
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
private Integer parseOptionalInteger(JsonNode node, String paramName) {
|
||||
if (node.isMissingNode() || node.isNull()) {
|
||||
return null;
|
||||
}
|
||||
if (!node.isIntegralNumber()) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"Value for parameter " + paramName + " is invalid. Reason: Must be an integer.", 400);
|
||||
}
|
||||
return node.asInt();
|
||||
}
|
||||
}
|
||||
@@ -210,7 +210,7 @@ public class SqsQueryHandler {
|
||||
private Response handleSendMessage(MultivaluedMap<String, String> params, String region) {
|
||||
String queueUrl = getParam(params, "QueueUrl");
|
||||
String body = getParam(params, "MessageBody");
|
||||
int delaySeconds = getIntParam(params, "DelaySeconds", 0);
|
||||
Integer delaySeconds = getIntegerParam(params, "DelaySeconds");
|
||||
String messageGroupId = getParam(params, "MessageGroupId");
|
||||
String messageDeduplicationId = getParam(params, "MessageDeduplicationId");
|
||||
|
||||
@@ -345,7 +345,7 @@ public class SqsQueryHandler {
|
||||
String queueUrl = getParam(params, "QueueUrl");
|
||||
var xml = new XmlBuilder();
|
||||
|
||||
record ParsedEntry(String id, String body, int delay, String groupId, String dedupId,
|
||||
record ParsedEntry(String id, String body, Integer delay, String groupId, String dedupId,
|
||||
Map<String, MessageAttributeValue> attributes, String awsTraceHeader) {}
|
||||
|
||||
List<ParsedEntry> parsedEntries = new ArrayList<>();
|
||||
@@ -354,7 +354,7 @@ public class SqsQueryHandler {
|
||||
String id = getParam(params, "SendMessageBatchRequestEntry." + i + ".Id");
|
||||
if (id == null) break;
|
||||
String body = getParam(params, "SendMessageBatchRequestEntry." + i + ".MessageBody");
|
||||
int delaySeconds = getIntParam(params, "SendMessageBatchRequestEntry." + i + ".DelaySeconds", 0);
|
||||
Integer delaySeconds = getIntegerParam(params, "SendMessageBatchRequestEntry." + i + ".DelaySeconds");
|
||||
String messageGroupId = getParam(params, "SendMessageBatchRequestEntry." + i + ".MessageGroupId");
|
||||
String messageDeduplicationId = getParam(params, "SendMessageBatchRequestEntry." + i + ".MessageDeduplicationId");
|
||||
|
||||
@@ -574,6 +574,17 @@ public class SqsQueryHandler {
|
||||
}
|
||||
}
|
||||
|
||||
private Integer getIntegerParam(MultivaluedMap<String, String> params, String name) {
|
||||
String value = params.getFirst(name);
|
||||
if (value == null) return null;
|
||||
try {
|
||||
return Integer.parseInt(value);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"Value for parameter " + name + " is invalid. Reason: Must be an integer.", 400);
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, String> extractAttributes(MultivaluedMap<String, String> params) {
|
||||
Map<String, String> attributes = new HashMap<>();
|
||||
for (int i = 1; ; i++) {
|
||||
|
||||
@@ -352,17 +352,17 @@ public class SqsService implements Resettable {
|
||||
return filtered;
|
||||
}
|
||||
|
||||
public Message sendMessage(String queueUrl, String body, int delaySeconds, String region) {
|
||||
public Message sendMessage(String queueUrl, String body, Integer delaySeconds, String region) {
|
||||
return sendMessage(queueUrl, body, delaySeconds, null, null, region);
|
||||
}
|
||||
|
||||
public Message sendMessage(String queueUrl, String body, int delaySeconds,
|
||||
public Message sendMessage(String queueUrl, String body, Integer delaySeconds,
|
||||
String messageGroupId, String messageDeduplicationId,
|
||||
String region) {
|
||||
return sendMessage(queueUrl, body, delaySeconds, messageGroupId, messageDeduplicationId, null, region);
|
||||
}
|
||||
|
||||
public Message sendMessage(String queueUrl, String body, int delaySeconds,
|
||||
public Message sendMessage(String queueUrl, String body, Integer delaySeconds,
|
||||
String messageGroupId, String messageDeduplicationId,
|
||||
Map<String, MessageAttributeValue> messageAttributes,
|
||||
String region) {
|
||||
@@ -370,7 +370,7 @@ public class SqsService implements Resettable {
|
||||
messageAttributes, null, region);
|
||||
}
|
||||
|
||||
public Message sendMessage(String queueUrl, String body, int delaySeconds,
|
||||
public Message sendMessage(String queueUrl, String body, Integer delaySeconds,
|
||||
String messageGroupId, String messageDeduplicationId,
|
||||
Map<String, MessageAttributeValue> messageAttributes,
|
||||
String awsTraceHeader,
|
||||
@@ -393,15 +393,16 @@ public class SqsService implements Resettable {
|
||||
// Resolve the effective delay:
|
||||
// - FIFO queues only support queue-level DelaySeconds per AWS SQS,
|
||||
// so any per-message value is ignored and we always use the
|
||||
// queue attribute. Without this, FIFO silently dropped the
|
||||
// queue-level default (issue #475).
|
||||
// - Standard queues honor per-message DelaySeconds when provided
|
||||
// (> 0). Applying the queue-level default on the standard path
|
||||
// requires distinguishing "omitted" from "explicit 0" in the
|
||||
// handlers, which the current int-parameter API cannot express;
|
||||
// that's left as follow-up work -- this patch only addresses
|
||||
// the FIFO regression called out in the issue.
|
||||
int effectiveDelaySeconds = queue.isFifo() ? queueDelaySeconds : delaySeconds;
|
||||
// queue attribute.
|
||||
// - Standard queues honor per-message DelaySeconds when explicitly
|
||||
// provided (non-null). When omitted (null), the queue-level
|
||||
// default applies.
|
||||
int effectiveDelaySeconds;
|
||||
if (queue.isFifo()) {
|
||||
effectiveDelaySeconds = queueDelaySeconds;
|
||||
} else {
|
||||
effectiveDelaySeconds = (delaySeconds != null) ? delaySeconds : queueDelaySeconds;
|
||||
}
|
||||
|
||||
// FIFO queue validation
|
||||
if (queue.isFifo()) {
|
||||
|
||||
Reference in new issue
Block a user