mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(sqs): match AWS on stale, gone and invalid receipt handles (#4730)
* fix(sqs): reject empty, malformed and foreign receipt handles * fix(sqs): accept receipt handles of gone and re-received messages * fix(sqs): reject expired FIFO receipt handles * fix(sqs): reject receipt handles that were never issued * chore(sqs): parse receipt handles once and share the handle checks * fix(sqs): sign receipt handles with a configurable secret * test(sqs): merge the receipt handle error tests into one table * fix(sqs): give a message moved by a move task a new message id
This commit is contained in:
1 parent
bd0f468d3e
commit
be21e86057
14 files changed
+478
-59
No files matched your search
@@ -1309,6 +1309,9 @@ public interface EmulatorConfig {
|
||||
|
||||
@WithDefault("false")
|
||||
boolean clearFifoDeduplicationCacheOnPurge();
|
||||
|
||||
@WithDefault("local-emulator-secret")
|
||||
String receiptHandleSecret();
|
||||
}
|
||||
|
||||
interface S3ServiceConfig {
|
||||
|
||||
@@ -6,11 +6,8 @@ import io.github.hectorvent.floci.services.sqs.model.Message;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -26,6 +23,7 @@ class GuardedMessageQueue {
|
||||
private final List<Message> messages;
|
||||
private final StorageBackend<String, List<Message>> messageStore;
|
||||
private final String storageKey;
|
||||
private final String receiptHandleSecret;
|
||||
private volatile boolean closed;
|
||||
|
||||
@FunctionalInterface
|
||||
@@ -40,13 +38,19 @@ class GuardedMessageQueue {
|
||||
}
|
||||
|
||||
GuardedMessageQueue(StorageBackend<String, List<Message>> messageStore, String storageKey) {
|
||||
this(new ArrayList<>(), messageStore, storageKey);
|
||||
this(new ArrayList<>(), messageStore, storageKey, ReceiptHandle.DEFAULT_SECRET);
|
||||
}
|
||||
|
||||
GuardedMessageQueue(List<Message> initial, StorageBackend<String, List<Message>> messageStore, String storageKey) {
|
||||
this(initial, messageStore, storageKey, ReceiptHandle.DEFAULT_SECRET);
|
||||
}
|
||||
|
||||
GuardedMessageQueue(List<Message> initial, StorageBackend<String, List<Message>> messageStore, String storageKey,
|
||||
String receiptHandleSecret) {
|
||||
this.messages = new ArrayList<>(initial);
|
||||
this.messageStore = messageStore;
|
||||
this.storageKey = storageKey;
|
||||
this.receiptHandleSecret = receiptHandleSecret;
|
||||
}
|
||||
|
||||
record ClaimResult(List<Message> claimed, List<Message> dlqCandidates) {
|
||||
@@ -117,7 +121,7 @@ class GuardedMessageQueue {
|
||||
return false;
|
||||
}
|
||||
|
||||
msg.setReceiptHandle(UUID.randomUUID().toString());
|
||||
msg.setReceiptHandle(ReceiptHandle.issue(storageKey, msg.getMessageId(), receiptHandleSecret).encode());
|
||||
msg.setVisibleAt(Instant.now().plusSeconds(effectiveTimeout));
|
||||
claimed.add(msg);
|
||||
return true;
|
||||
@@ -160,37 +164,59 @@ class GuardedMessageQueue {
|
||||
}
|
||||
}
|
||||
|
||||
Optional<Message> removeByReceiptHandle(String receiptHandle) {
|
||||
enum HandleResult { APPLIED, MESSAGE_GONE, HANDLE_EXPIRED }
|
||||
|
||||
record Removal(HandleResult result, Message message) {
|
||||
}
|
||||
|
||||
Removal removeByReceiptHandle(ReceiptHandle handle, boolean fifo) {
|
||||
try (Guard _ = hold()) {
|
||||
Message removed = null;
|
||||
for (Iterator<Message> it = messages.iterator(); it.hasNext(); ) {
|
||||
Message m = it.next();
|
||||
if (receiptHandle.equals(m.getReceiptHandle())) {
|
||||
removed = m;
|
||||
it.remove();
|
||||
break;
|
||||
}
|
||||
Message msg = findByMessageId(handle.messageId());
|
||||
HandleResult result = checkHandle(msg, handle, fifo);
|
||||
if (result != HandleResult.APPLIED) {
|
||||
return new Removal(result, null);
|
||||
}
|
||||
if (removed != null) {
|
||||
persist();
|
||||
}
|
||||
return Optional.ofNullable(removed);
|
||||
messages.remove(msg);
|
||||
persist();
|
||||
return new Removal(HandleResult.APPLIED, msg);
|
||||
}
|
||||
}
|
||||
|
||||
boolean changeVisibility(String receiptHandle, int visibilityTimeout) {
|
||||
HandleResult changeVisibility(ReceiptHandle handle, int visibilityTimeout, boolean fifo) {
|
||||
try (Guard _ = hold()) {
|
||||
for (Message msg : messages) {
|
||||
if (receiptHandle.equals(msg.getReceiptHandle())) {
|
||||
msg.setVisibleAt(Instant.now().plusSeconds(visibilityTimeout));
|
||||
persist();
|
||||
return true;
|
||||
}
|
||||
Message msg = findByMessageId(handle.messageId());
|
||||
HandleResult result = checkHandle(msg, handle, fifo);
|
||||
if (result == HandleResult.APPLIED) {
|
||||
msg.setVisibleAt(Instant.now().plusSeconds(visibilityTimeout));
|
||||
persist();
|
||||
}
|
||||
return false;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private Message findByMessageId(String messageId) {
|
||||
for (Message msg : messages) {
|
||||
if (messageId.equals(msg.getMessageId())) {
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* On a standard queue an older handle of the message still works. On a FIFO queue only the
|
||||
* handle of the receive still in flight does.
|
||||
*/
|
||||
private static HandleResult checkHandle(Message msg, ReceiptHandle handle, boolean fifo) {
|
||||
if (msg == null) {
|
||||
return HandleResult.MESSAGE_GONE;
|
||||
}
|
||||
if (fifo && (!handle.encode().equals(msg.getReceiptHandle()) || msg.isVisible())) {
|
||||
return HandleResult.HANDLE_EXPIRED;
|
||||
}
|
||||
return HandleResult.APPLIED;
|
||||
}
|
||||
|
||||
void removeMessages(List<Message> toRemove) {
|
||||
try (Guard _ = hold()) {
|
||||
messages.removeAll(toRemove);
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
package io.github.hectorvent.floci.services.sqs;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.util.HexFormat;
|
||||
import java.util.UUID;
|
||||
import javax.crypto.Mac;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
|
||||
/**
|
||||
* Floci's receipt handle. The fields are readable, and the signature rejects a handle that was
|
||||
* edited or built by hand, as AWS does.
|
||||
*/
|
||||
record ReceiptHandle(String region, String accountId, String queueName, String messageId, String receipt,
|
||||
String signature) {
|
||||
|
||||
static final String DEFAULT_SECRET = "local-emulator-secret";
|
||||
|
||||
private static final String[] KEYS = {"region", "account", "queue", "messageId", "receipt", "signature"};
|
||||
|
||||
static ReceiptHandle issue(String storageKey, String messageId, String secret) {
|
||||
String[] queue = queueParts(storageKey);
|
||||
String receipt = UUID.randomUUID().toString();
|
||||
String signature = sign(body(queue[0], queue[1], queue[2], messageId, receipt), secret);
|
||||
return new ReceiptHandle(queue[0], queue[1], queue[2], messageId, receipt, signature);
|
||||
}
|
||||
|
||||
String encode() {
|
||||
return body(region, accountId, queueName, messageId, receipt) + ":signature=" + signature;
|
||||
}
|
||||
|
||||
/** Returns null when {@code value} is not in this format. */
|
||||
static ReceiptHandle parse(String value) {
|
||||
String[] parts = value.split(":", -1);
|
||||
if (parts.length != KEYS.length) {
|
||||
return null;
|
||||
}
|
||||
String[] values = new String[KEYS.length];
|
||||
for (int i = 0; i < KEYS.length; i++) {
|
||||
String prefix = KEYS[i] + "=";
|
||||
if (!parts[i].startsWith(prefix)) {
|
||||
return null;
|
||||
}
|
||||
values[i] = parts[i].substring(prefix.length());
|
||||
}
|
||||
return new ReceiptHandle(values[0], values[1], values[2], values[3], values[4], values[5]);
|
||||
}
|
||||
|
||||
boolean isSignedWith(String secret) {
|
||||
return signature.equals(sign(body(region, accountId, queueName, messageId, receipt), secret));
|
||||
}
|
||||
|
||||
boolean belongsTo(String storageKey) {
|
||||
String[] queue = queueParts(storageKey);
|
||||
return region.equals(queue[0]) && accountId.equals(queue[1]) && queueName.equals(queue[2]);
|
||||
}
|
||||
|
||||
/** Splits a storage key of the form {@code region::/accountId/queueName}. */
|
||||
private static String[] queueParts(String storageKey) {
|
||||
if (storageKey == null) {
|
||||
return new String[] {"", "", ""};
|
||||
}
|
||||
int separator = storageKey.indexOf("::");
|
||||
String region = separator < 0 ? "" : storageKey.substring(0, separator);
|
||||
String path = separator < 0 ? storageKey : storageKey.substring(separator + 2);
|
||||
String trimmed = path.startsWith("/") ? path.substring(1) : path;
|
||||
int slash = trimmed.indexOf('/');
|
||||
String accountId = slash < 0 ? "" : trimmed.substring(0, slash);
|
||||
return new String[] {region, accountId, trimmed.substring(slash + 1)};
|
||||
}
|
||||
|
||||
private static String body(String region, String accountId, String queueName, String messageId,
|
||||
String receipt) {
|
||||
return "region=" + region + ":account=" + accountId + ":queue=" + queueName
|
||||
+ ":messageId=" + messageId + ":receipt=" + receipt;
|
||||
}
|
||||
|
||||
private static String sign(String value, String secret) {
|
||||
try {
|
||||
Mac mac = Mac.getInstance("HmacSHA256");
|
||||
mac.init(new SecretKeySpec(secret.getBytes(StandardCharsets.UTF_8), "HmacSHA256"));
|
||||
return HexFormat.of().formatHex(mac.doFinal(value.getBytes(StandardCharsets.UTF_8)));
|
||||
} catch (GeneralSecurityException e) {
|
||||
throw new IllegalStateException("HmacSHA256 is not available", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -329,7 +329,7 @@ public class SqsJsonHandler {
|
||||
String id = entry.path("Id").asText();
|
||||
String receiptHandle = entry.path("ReceiptHandle").asText(null);
|
||||
try {
|
||||
sqsService.deleteMessage(queueUrl, receiptHandle, region);
|
||||
sqsService.deleteMessageInBatch(queueUrl, receiptHandle, region);
|
||||
ObjectNode success = objectMapper.createObjectNode();
|
||||
success.put("Id", id);
|
||||
successful.add(success);
|
||||
|
||||
@@ -332,7 +332,7 @@ public class SqsQueryHandler {
|
||||
if (id == null) break;
|
||||
String receiptHandle = getParam(params, "DeleteMessageBatchRequestEntry." + i + ".ReceiptHandle");
|
||||
try {
|
||||
sqsService.deleteMessage(queueUrl, receiptHandle, region);
|
||||
sqsService.deleteMessageInBatch(queueUrl, receiptHandle, region);
|
||||
xml.start("DeleteMessageBatchResultEntry").elem("Id", id).end("DeleteMessageBatchResultEntry");
|
||||
} catch (AwsException e) {
|
||||
xml.start("BatchResultErrorEntry")
|
||||
|
||||
@@ -270,6 +270,7 @@ public class SqsService implements Resettable, ResourceProvider {
|
||||
private final boolean clearFifoDeduplicationCacheOnPurge;
|
||||
private final SnsService snsService;
|
||||
private final Clock clock;
|
||||
private final String receiptHandleSecret;
|
||||
|
||||
public SqsService(StorageFactory storageFactory, EmulatorConfig config, RegionResolver regionResolver,
|
||||
SnsService snsService) {
|
||||
@@ -298,7 +299,8 @@ public class SqsService implements Resettable, ResourceProvider {
|
||||
regionResolver,
|
||||
config.services().sqs().clearFifoDeduplicationCacheOnPurge(),
|
||||
snsService,
|
||||
clock
|
||||
clock,
|
||||
config.services().sqs().receiptHandleSecret()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -349,6 +351,17 @@ public class SqsService implements Resettable, ResourceProvider {
|
||||
int defaultVisibilityTimeout, int maxMessageSize, String baseUrl,
|
||||
RegionResolver regionResolver, boolean clearFifoDeduplicationCacheOnPurge,
|
||||
SnsService snsService, Clock clock) {
|
||||
this(queueStore, messageStore, dedupStore, dedupIdentityStore, defaultVisibilityTimeout, maxMessageSize,
|
||||
baseUrl, regionResolver, clearFifoDeduplicationCacheOnPurge, snsService, clock,
|
||||
ReceiptHandle.DEFAULT_SECRET);
|
||||
}
|
||||
|
||||
SqsService(StorageBackend<String, Queue> queueStore, StorageBackend<String, List<Message>> messageStore,
|
||||
StorageBackend<String, Map<String, Long>> dedupStore,
|
||||
StorageBackend<String, Map<String, Map<String, String>>> dedupIdentityStore,
|
||||
int defaultVisibilityTimeout, int maxMessageSize, String baseUrl,
|
||||
RegionResolver regionResolver, boolean clearFifoDeduplicationCacheOnPurge,
|
||||
SnsService snsService, Clock clock, String receiptHandleSecret) {
|
||||
this.queueStore = queueStore;
|
||||
this.messageStore = messageStore;
|
||||
this.dedupStore = dedupStore;
|
||||
@@ -361,6 +374,7 @@ public class SqsService implements Resettable, ResourceProvider {
|
||||
this.clearFifoDeduplicationCacheOnPurge = clearFifoDeduplicationCacheOnPurge;
|
||||
this.snsService = snsService;
|
||||
this.clock = clock;
|
||||
this.receiptHandleSecret = receiptHandleSecret;
|
||||
this.moveTasksByHandle = new MoveTaskStore(clock);
|
||||
loadPersistedMessages();
|
||||
loadPersistedDedup();
|
||||
@@ -391,11 +405,12 @@ public class SqsService implements Resettable, ResourceProvider {
|
||||
}
|
||||
if (messageStore instanceof AccountAwareStorageBackend<List<Message>> aware) {
|
||||
aware.scanAllAccountsAsMap().forEach((key, msgs) ->
|
||||
messagesByQueue.put(key, new GuardedMessageQueue(msgs, messageStore, key)));
|
||||
messagesByQueue.put(key, new GuardedMessageQueue(msgs, messageStore, key, receiptHandleSecret)));
|
||||
} else {
|
||||
for (String key : messageStore.keys()) {
|
||||
messageStore.get(key).ifPresent(msgs ->
|
||||
messagesByQueue.put(key, new GuardedMessageQueue(msgs, messageStore, key)));
|
||||
messagesByQueue.put(key,
|
||||
new GuardedMessageQueue(msgs, messageStore, key, receiptHandleSecret)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -467,7 +482,7 @@ public class SqsService implements Resettable, ResourceProvider {
|
||||
|
||||
private GuardedMessageQueue getOrCreateQueue(String storageKey) {
|
||||
return messagesByQueue.computeIfAbsent(storageKey,
|
||||
k -> new GuardedMessageQueue(messageStore, k));
|
||||
k -> new GuardedMessageQueue(new ArrayList<>(), messageStore, k, receiptHandleSecret));
|
||||
}
|
||||
|
||||
private void persistDedup(String storageKey) {
|
||||
@@ -623,7 +638,8 @@ public class SqsService implements Resettable, ResourceProvider {
|
||||
}
|
||||
|
||||
queueStore.put(storageKey, queue);
|
||||
messagesByQueue.put(storageKey, new GuardedMessageQueue(messageStore, storageKey));
|
||||
messagesByQueue.put(storageKey,
|
||||
new GuardedMessageQueue(new ArrayList<>(), messageStore, storageKey, receiptHandleSecret));
|
||||
LOG.infov("Created {0} queue: {1} in region {2}", queue.isFifo() ? "FIFO" : "standard", queueName, region);
|
||||
return queue;
|
||||
}
|
||||
@@ -1244,37 +1260,93 @@ public class SqsService implements Resettable, ResourceProvider {
|
||||
}
|
||||
|
||||
public void deleteMessage(String queueUrl, String receiptHandle, String region) {
|
||||
deleteMessage(queueUrl, receiptHandle, region, false);
|
||||
}
|
||||
|
||||
public void deleteMessageInBatch(String queueUrl, String receiptHandle, String region) {
|
||||
deleteMessage(queueUrl, receiptHandle, region, true);
|
||||
}
|
||||
|
||||
private void deleteMessage(String queueUrl, String receiptHandle, String region, boolean inBatch) {
|
||||
String storageKey = regionKey(region, queueUrl);
|
||||
if (getQueueByUrl(storageKey, queueUrl).isEmpty()) {
|
||||
throw new AwsException("AWS.SimpleQueueService.NonExistentQueue",
|
||||
"The specified queue does not exist.", 400);
|
||||
}
|
||||
Queue queue = getQueueByUrl(storageKey, queueUrl)
|
||||
.orElseThrow(() -> new AwsException("AWS.SimpleQueueService.NonExistentQueue",
|
||||
"The specified queue does not exist.", 400));
|
||||
ReceiptHandle handle = checkReceiptHandle(storageKey, receiptHandle, inBatch);
|
||||
|
||||
Optional<Message> removed = getOrCreateQueue(storageKey).removeByReceiptHandle(receiptHandle);
|
||||
|
||||
if (removed.isEmpty()) {
|
||||
throw new AwsException("ReceiptHandleIsInvalid",
|
||||
"The input receipt handle is not a valid receipt handle.", 400);
|
||||
GuardedMessageQueue.Removal removal =
|
||||
getOrCreateQueue(storageKey).removeByReceiptHandle(handle, queue.isFifo());
|
||||
rejectUnusableHandle(removal.result(), receiptHandle, inBatch);
|
||||
// AWS reports success for a message that is already gone.
|
||||
if (removal.result() == GuardedMessageQueue.HandleResult.MESSAGE_GONE) {
|
||||
LOG.debugv("No message for receipt handle {0}", receiptHandle);
|
||||
return;
|
||||
}
|
||||
LOG.debugv("Deleted message with receipt handle {0}", receiptHandle);
|
||||
if (LOG.isTraceEnabled()) {
|
||||
Message m = removed.get();
|
||||
Message m = removal.message();
|
||||
LOG.tracev("Deleted message {0} from queue {1} body={2}",
|
||||
m.getMessageId(), queueUrl, m.getBody());
|
||||
}
|
||||
}
|
||||
|
||||
public void changeMessageVisibility(String queueUrl, String receiptHandle, int visibilityTimeout, String region) {
|
||||
String storageKey = regionKey(region, queueUrl);
|
||||
ensureQueueExists(storageKey);
|
||||
changeMessageVisibility(queueUrl, receiptHandle, visibilityTimeout, region, false);
|
||||
}
|
||||
|
||||
boolean found = getOrCreateQueue(storageKey).changeVisibility(receiptHandle, visibilityTimeout);
|
||||
if (!found) {
|
||||
throw new AwsException("ReceiptHandleIsInvalid",
|
||||
"The input receipt handle is not a valid receipt handle.", 400);
|
||||
private void changeMessageVisibility(String queueUrl, String receiptHandle, int visibilityTimeout,
|
||||
String region, boolean inBatch) {
|
||||
String storageKey = regionKey(region, queueUrl);
|
||||
Queue queue = queueStore.get(storageKey)
|
||||
.orElseThrow(() -> new AwsException("AWS.SimpleQueueService.NonExistentQueue",
|
||||
"The specified queue does not exist.", 400));
|
||||
ReceiptHandle handle = checkReceiptHandle(storageKey, receiptHandle, inBatch);
|
||||
|
||||
GuardedMessageQueue.HandleResult result =
|
||||
getOrCreateQueue(storageKey).changeVisibility(handle, visibilityTimeout, queue.isFifo());
|
||||
rejectUnusableHandle(result, receiptHandle, inBatch);
|
||||
if (result == GuardedMessageQueue.HandleResult.MESSAGE_GONE) {
|
||||
throw invalidReceiptHandle(receiptHandle,
|
||||
"Message does not exist or is not available for visibility timeout change", inBatch);
|
||||
}
|
||||
}
|
||||
|
||||
private static void rejectUnusableHandle(GuardedMessageQueue.HandleResult result, String receiptHandle,
|
||||
boolean inBatch) {
|
||||
if (result == GuardedMessageQueue.HandleResult.HANDLE_EXPIRED) {
|
||||
throw invalidReceiptHandle(receiptHandle, "The receipt handle has expired", inBatch);
|
||||
}
|
||||
}
|
||||
|
||||
private static AwsException invalidReceiptHandle(String receiptHandle, String reason, boolean inBatch) {
|
||||
if (inBatch) {
|
||||
return new AwsException("ReceiptHandleIsInvalid", reason, 400);
|
||||
}
|
||||
return new AwsException("InvalidParameterValue",
|
||||
"Value " + receiptHandle + " for parameter ReceiptHandle is invalid. Reason: " + reason + ".", 400);
|
||||
}
|
||||
|
||||
/** A batch entry reports every receipt handle error under the ReceiptHandleIsInvalid code. */
|
||||
private ReceiptHandle checkReceiptHandle(String storageKey, String receiptHandle, boolean inBatch) {
|
||||
if (receiptHandle == null || receiptHandle.isEmpty()) {
|
||||
throw new AwsException(inBatch ? "ReceiptHandleIsInvalid" : "MissingParameter",
|
||||
"The request must contain the parameter ReceiptHandle.", 400);
|
||||
}
|
||||
ReceiptHandle parsed = ReceiptHandle.parse(receiptHandle);
|
||||
if (parsed == null) {
|
||||
throw new AwsException("ReceiptHandleIsInvalid", "The input receipt handle is invalid.", 400);
|
||||
}
|
||||
if (!parsed.isSignedWith(receiptHandleSecret) || !parsed.belongsTo(storageKey)) {
|
||||
throw handleNotValidForQueue(receiptHandle);
|
||||
}
|
||||
return parsed;
|
||||
}
|
||||
|
||||
private static AwsException handleNotValidForQueue(String receiptHandle) {
|
||||
return new AwsException("ReceiptHandleIsInvalid",
|
||||
"The receipt handle \"" + receiptHandle + "\" is not valid for this queue.", 400);
|
||||
}
|
||||
|
||||
public void purgeQueue(String queueUrl, String region) {
|
||||
String storageKey = regionKey(region, queueUrl);
|
||||
ensureQueueExists(storageKey);
|
||||
@@ -1597,7 +1669,7 @@ public class SqsService implements Resettable, ResourceProvider {
|
||||
List<BatchResultEntry> results = new ArrayList<>();
|
||||
for (ChangeVisibilityBatchEntry entry : entries) {
|
||||
try {
|
||||
changeMessageVisibility(queueUrl, entry.receiptHandle(), entry.visibilityTimeout(), region);
|
||||
changeMessageVisibility(queueUrl, entry.receiptHandle(), entry.visibilityTimeout(), region, true);
|
||||
results.add(new BatchResultEntry(entry.id(), true, null, null));
|
||||
} catch (AwsException e) {
|
||||
results.add(new BatchResultEntry(entry.id(), false, e.getErrorCode(), e.getMessage()));
|
||||
|
||||
@@ -69,12 +69,13 @@ public class Message {
|
||||
this.md5OfBody = computeMd5(body);
|
||||
}
|
||||
|
||||
/** A copy for delivery to another queue by StartMessageMoveTask: identity and content carry
|
||||
* over; per-receive state (receive count, first-receive timestamp, receipt handle, visibility)
|
||||
* starts over. The source instance is untouched so a failed delivery can put it back as it was. */
|
||||
/** A copy for delivery to another queue by StartMessageMoveTask. The content carries over. AWS
|
||||
* gives it a new message id, and per-receive state (receive count, first-receive timestamp,
|
||||
* receipt handle, visibility) starts over. The source instance is untouched so a failed
|
||||
* delivery can put it back as it was. */
|
||||
public Message copyForRedrive() {
|
||||
Message copy = new Message();
|
||||
copy.messageId = messageId;
|
||||
copy.messageId = UUID.randomUUID().toString();
|
||||
copy.body = body;
|
||||
copy.messageAttributes = messageAttributes == null ? new HashMap<>() : new HashMap<>(messageAttributes);
|
||||
copy.sentTimestamp = sentTimestamp;
|
||||
|
||||
Reference in new issue
Block a user