-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sdk): dead letter queue support for queues (#6060)
⛔ As the dead-letter queue linked to the function is a specific case of AWS, I will remove it from the scope of this PR. - [x] dlq (with retries) for queue (tf-aws / awscdk) - [x] dlq (with retries) for queue (sim) ~dlq for function (tf-aws / awscdk)~ ~dlq for function (sim)~ Closes #6033 ## Checklist - [x] Title matches [Winglang's style guide](https://www.winglang.io/contributing/start-here/pull_requests#how-are-pull-request-titles-formatted) - [x] Description explains motivation and solution - [x] Tests added (always) - [ ] Docs updated (only required for features) - [ ] Added `pr/e2e-full` label if this feature requires end-to-end testing *By submitting this pull request, I confirm that my contribution is made under the terms of the [Wing Cloud Contribution License](https://github.com/winglang/wing/blob/main/CONTRIBUTION_LICENSE.md)*.
- Loading branch information
1 parent
8d9d77e
commit 2dea835
Showing
33 changed files
with
777 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
bring cloud; | ||
bring util; | ||
|
||
let counter_received_messages = new cloud.Counter(); | ||
|
||
let dlq_without_retries = new cloud.Queue() as "dlq without retries"; | ||
let queue_without_retries = new cloud.Queue( | ||
dlq: { queue: dlq_without_retries } | ||
) as "queue without retries"; | ||
queue_without_retries.setConsumer(inflight (msg: str) => { | ||
counter_received_messages.inc(1, msg); | ||
if msg == "fail" { | ||
throw "error"; | ||
} | ||
}); | ||
|
||
|
||
new std.Test( | ||
inflight () => { | ||
queue_without_retries.push("Hello"); | ||
queue_without_retries.push("fail"); | ||
queue_without_retries.push("World!"); | ||
|
||
// wait until it executes once. | ||
assert(util.waitUntil(inflight () => { return counter_received_messages.peek("Hello") == 1; })); | ||
assert(util.waitUntil(inflight () => { return counter_received_messages.peek("World!") == 1; })); | ||
assert(util.waitUntil(inflight () => { return counter_received_messages.peek("fail") == 1; })); | ||
|
||
// check if the "fail" message has arrived at the dead-letter queue | ||
assert(util.waitUntil(inflight () => { return dlq_without_retries.pop() == "fail"; })); | ||
}, | ||
// To make this test work on AWS, it's necessary to set a high timeout | ||
// because if the message fails, we have to wait for the visibility timeout | ||
// to expire in order to retrieve the same message from the queue again. | ||
timeout: 5m) as "one execution and send fail message to dead-letter queue"; | ||
|
||
let dlq_with_retries = new cloud.Queue() as "dlq with retries"; | ||
let queue_with_retries = new cloud.Queue( | ||
dlq: { | ||
queue: dlq_with_retries, | ||
maxDeliveryAttempts: 2 | ||
} | ||
) as "queue with retries"; | ||
queue_with_retries.setConsumer(inflight (msg: str) => { | ||
counter_received_messages.inc(1, msg); | ||
if msg == "fail" { | ||
throw "error"; | ||
} | ||
}); | ||
|
||
new std.Test(inflight () => { | ||
queue_with_retries.push("Hello"); | ||
queue_with_retries.push("fail"); | ||
queue_with_retries.push("World!"); | ||
|
||
// wait until it executes once and retry one more times. | ||
assert(util.waitUntil(inflight () => { return counter_received_messages.peek("Hello") == 1; })); | ||
assert(util.waitUntil(inflight () => { return counter_received_messages.peek("World!") == 1; })); | ||
assert(util.waitUntil(inflight () => { return counter_received_messages.peek("fail") == 2; })); | ||
|
||
// check if the "fail" message has arrived at the dead-letter queue | ||
assert(util.waitUntil(inflight () => { return dlq_with_retries.pop() == "fail"; })); | ||
}, timeout: 5m) as "one execution, two retries and send the fail message to dead-letter queue"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.