sqs_extended_client 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +8 -0
- data/LICENSE.txt +204 -0
- data/NOTICE +20 -0
- data/README.md +182 -0
- data/lib/sqs_extended_client/client.rb +179 -0
- data/lib/sqs_extended_client/configuration.rb +66 -0
- data/lib/sqs_extended_client/errors.rb +14 -0
- data/lib/sqs_extended_client/payload_pointer.rb +59 -0
- data/lib/sqs_extended_client/payload_store.rb +32 -0
- data/lib/sqs_extended_client/receipt_handle.rb +43 -0
- data/lib/sqs_extended_client/version.rb +5 -0
- data/lib/sqs_extended_client.rb +18 -0
- metadata +90 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: f4fa6e3026a96530fc60de516f4817f5d2ff08f106f48fef058728e83aafa0b6
|
|
4
|
+
data.tar.gz: 192fcc74a733f1780e0d50fa6092ad29e462010128c897b8111f27135b675b87
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: adbb8b60ba77329fb74f8a52d69397ac41dff4263cb5a932bcca4f158041d766987480aad947a6b15ac91f2e8d6a2deeb660025030cea82fc70cfa6f19cf8e65
|
|
7
|
+
data.tar.gz: a5d05a27eee220902bec964d8645f1f77c4a9bdea6da9461b676451d5cb42618bd52549027f502dbb764e79aebb0425c106ef47d003d232ebc5ccd4203952a83
|
data/CHANGELOG.md
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
203
|
+
|
|
204
|
+
Copyright 2026 Ngoc Bui
|
data/NOTICE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
sqs_extended_client
|
|
2
|
+
Copyright 2026 Ngoc Bui
|
|
3
|
+
|
|
4
|
+
This product is an independent Ruby implementation of the payload offloading
|
|
5
|
+
protocol introduced by the Amazon SQS Extended Client Library for Java:
|
|
6
|
+
|
|
7
|
+
https://github.com/awslabs/amazon-sqs-java-extended-client-lib
|
|
8
|
+
Copyright 2010-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
9
|
+
Licensed under the Apache License, Version 2.0.
|
|
10
|
+
|
|
11
|
+
The wire format reproduced here -- the ExtendedPayloadSize message attribute,
|
|
12
|
+
the PayloadS3Pointer message body and the receipt handle markers -- originates
|
|
13
|
+
in that library and in its supporting library:
|
|
14
|
+
|
|
15
|
+
https://github.com/awslabs/payload-offloading-java-common-lib-for-aws
|
|
16
|
+
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
17
|
+
Licensed under the Apache License, Version 2.0.
|
|
18
|
+
|
|
19
|
+
No source code from those projects is included in this product. This project is
|
|
20
|
+
not affiliated with, endorsed by, or sponsored by Amazon Web Services.
|
data/README.md
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
# sqs_extended_client
|
|
2
|
+
|
|
3
|
+
Send and receive Amazon SQS messages larger than the 256 KB limit by storing the body in S3
|
|
4
|
+
and putting a small pointer on the queue instead. It is a wrapper around `Aws::SQS::Client`,
|
|
5
|
+
so anything it does not need to touch is delegated straight through.
|
|
6
|
+
|
|
7
|
+
The wire format matches the AWS
|
|
8
|
+
[Java](https://github.com/awslabs/amazon-sqs-java-extended-client-lib) and
|
|
9
|
+
[Python](https://github.com/awslabs/amazon-sqs-python-extended-client-lib) extended clients:
|
|
10
|
+
a Ruby producer can publish to a queue a Java consumer drains, and the other way round.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```ruby
|
|
15
|
+
gem "sqs_extended_client"
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Requires Ruby 3.1 or newer, and is tested on Ruby 4.
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
Build the client once and hold onto it. Pass your own SQS and S3 clients when you need to set
|
|
23
|
+
region, credentials or retries; every other keyword is an option from the table below.
|
|
24
|
+
|
|
25
|
+
```ruby
|
|
26
|
+
client = SqsExtendedClient::Client.new(
|
|
27
|
+
bucket_name: "my-payload-bucket",
|
|
28
|
+
sqs_client: Aws::SQS::Client.new(region: "ap-southeast-1"),
|
|
29
|
+
s3_client: Aws::S3::Client.new(region: "ap-southeast-1")
|
|
30
|
+
)
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Sending
|
|
34
|
+
|
|
35
|
+
Send as you would with the plain SQS client. Bodies under the threshold go straight to the
|
|
36
|
+
queue; anything larger is written to S3 first and the queue gets a pointer.
|
|
37
|
+
|
|
38
|
+
```ruby
|
|
39
|
+
client.send_message(
|
|
40
|
+
queue_url: queue_url,
|
|
41
|
+
message_body: JSON.generate(order), # any size
|
|
42
|
+
message_attributes: {
|
|
43
|
+
"event_type" => { data_type: "String", string_value: "order.created" }
|
|
44
|
+
}
|
|
45
|
+
)
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Batches work the same way, each entry is offloaded on its own:
|
|
49
|
+
|
|
50
|
+
```ruby
|
|
51
|
+
client.send_message_batch(
|
|
52
|
+
queue_url: queue_url,
|
|
53
|
+
entries: orders.each_with_index.map do |order, index|
|
|
54
|
+
{ id: index.to_s, message_body: JSON.generate(order) }
|
|
55
|
+
end
|
|
56
|
+
)
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Remember that SQS sizes a batch by what actually goes on the queue. Offloaded entries are only
|
|
60
|
+
a pointer each, so a batch of large payloads still fits comfortably under the 256 KB batch cap.
|
|
61
|
+
|
|
62
|
+
### Polling
|
|
63
|
+
|
|
64
|
+
A worker loop. `receive_message` fetches the body back from S3 before you see it, and
|
|
65
|
+
`delete_message` removes the S3 object along with the message:
|
|
66
|
+
|
|
67
|
+
```ruby
|
|
68
|
+
loop do
|
|
69
|
+
response = client.receive_message(
|
|
70
|
+
queue_url: queue_url,
|
|
71
|
+
max_number_of_messages: 10,
|
|
72
|
+
wait_time_seconds: 20, # long polling, keeps the loop from spinning
|
|
73
|
+
visibility_timeout: 60 # must comfortably exceed your processing time
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
response.messages.each do |message|
|
|
77
|
+
process(JSON.parse(message.body))
|
|
78
|
+
|
|
79
|
+
client.delete_message(queue_url: queue_url, receipt_handle: message.receipt_handle)
|
|
80
|
+
rescue StandardError => e
|
|
81
|
+
# Leave the message alone and let SQS redeliver it after the visibility timeout.
|
|
82
|
+
logger.error("failed to process #{message.message_id}: #{e.message}")
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Delete only after the work succeeded. Deleting first would drop the S3 object too, so a
|
|
88
|
+
redelivery would arrive pointing at an object that is no longer there.
|
|
89
|
+
|
|
90
|
+
To delete in batches, pass the receipt handles through unchanged — the pointer travels inside
|
|
91
|
+
them, and each entry is cleaned up from S3 individually:
|
|
92
|
+
|
|
93
|
+
```ruby
|
|
94
|
+
client.delete_message_batch(
|
|
95
|
+
queue_url: queue_url,
|
|
96
|
+
entries: processed.each_with_index.map do |message, index|
|
|
97
|
+
{ id: index.to_s, receipt_handle: message.receipt_handle }
|
|
98
|
+
end
|
|
99
|
+
)
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
If processing runs long, extend the lease with `change_message_visibility`; it accepts the
|
|
103
|
+
receipt handle you were given and strips the pointer out before the call reaches SQS:
|
|
104
|
+
|
|
105
|
+
```ruby
|
|
106
|
+
client.change_message_visibility(
|
|
107
|
+
queue_url: queue_url,
|
|
108
|
+
receipt_handle: message.receipt_handle,
|
|
109
|
+
visibility_timeout: 300
|
|
110
|
+
)
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Options
|
|
114
|
+
|
|
115
|
+
| Option | Default | Meaning |
|
|
116
|
+
| --- | --- | --- |
|
|
117
|
+
| `bucket_name` | required | S3 bucket the payloads are written to. |
|
|
118
|
+
| `payload_size_threshold` | `262_144` | Offload once body + attributes exceed this many bytes. |
|
|
119
|
+
| `always_through_s3` | `false` | Offload every message regardless of size. |
|
|
120
|
+
| `cleanup_s3_payload` | `true` | Delete the S3 object when the message is deleted. |
|
|
121
|
+
| `ignore_payload_not_found` | `false` | On a missing S3 object, delete the SQS message and skip it instead of raising. |
|
|
122
|
+
| `use_legacy_reserved_attribute_name` | `false` | Flag messages with `SQSLargePayloadSize` instead of `ExtendedPayloadSize`. |
|
|
123
|
+
| `s3_key_prefix` | `""` | Prefix for generated keys, e.g. `"payloads/"`. |
|
|
124
|
+
| `s3_put_object_options` | `{}` | Merged into `put_object`, e.g. `{ server_side_encryption: "aws:kms" }`. |
|
|
125
|
+
|
|
126
|
+
## How it works
|
|
127
|
+
|
|
128
|
+
An offloaded message carries a `Number` attribute named `ExtendedPayloadSize` holding the
|
|
129
|
+
original body size, and its body is replaced by
|
|
130
|
+
|
|
131
|
+
```json
|
|
132
|
+
["software.amazon.payloadoffloading.PayloadS3Pointer",{"s3BucketName":"...","s3Key":"..."}]
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
The first element is the Java class name the original implementation serialized with. This
|
|
136
|
+
gem always writes the current name and ignores whatever it reads, so messages from the legacy
|
|
137
|
+
v1 Java client — which used `com.amazon.sqs.javamessaging.MessageS3Pointer` and the
|
|
138
|
+
`SQSLargePayloadSize` attribute — are read without any extra configuration.
|
|
139
|
+
|
|
140
|
+
`delete_message` only receives a receipt handle, so on receive the bucket and key are spliced
|
|
141
|
+
into the handle between markers:
|
|
142
|
+
|
|
143
|
+
```
|
|
144
|
+
-..s3BucketName..-{bucket}-..s3BucketName..--..s3Key..-{key}-..s3Key..-{real handle}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
`delete_message`, `delete_message_batch` and `change_message_visibility` strip that back off
|
|
148
|
+
before the call reaches SQS. Because a message received here may be deleted by a Java or
|
|
149
|
+
Python consumer (and vice versa), those markers are part of the wire contract.
|
|
150
|
+
|
|
151
|
+
Only the operations that need it are overridden: `send_message`, `send_message_batch`,
|
|
152
|
+
`receive_message`, `delete_message`, `delete_message_batch`, `change_message_visibility` and
|
|
153
|
+
`change_message_visibility_batch`. Every other SQS call is forwarded unchanged.
|
|
154
|
+
|
|
155
|
+
## Caveats
|
|
156
|
+
|
|
157
|
+
- SQS allows 10 message attributes and the reserved one takes a slot, so an offloaded message
|
|
158
|
+
may carry at most 9 of your own.
|
|
159
|
+
- Nothing here expires S3 objects on its own. Set a lifecycle rule on the bucket so payloads
|
|
160
|
+
from messages that were never consumed do not accumulate.
|
|
161
|
+
- The consumer needs `s3:GetObject` and, for cleanup, `s3:DeleteObject` on the bucket.
|
|
162
|
+
- On a FIFO queue with content based deduplication, the hash is taken over the pointer, which
|
|
163
|
+
is unique per send. Pass an explicit `message_deduplication_id` for offloaded messages.
|
|
164
|
+
- `receive_message` returns a freshly built `Aws::SQS::Types::ReceiveMessageResult`, so the
|
|
165
|
+
Seahorse response context (`.context`, `#successful?`) is not carried through.
|
|
166
|
+
|
|
167
|
+
## Credits
|
|
168
|
+
|
|
169
|
+
The design is not original to this gem. The approach, and every byte of the wire format it
|
|
170
|
+
speaks, come from the [Amazon SQS Extended Client Library for Java](https://github.com/awslabs/amazon-sqs-java-extended-client-lib)
|
|
171
|
+
and its supporting [payload offloading library](https://github.com/awslabs/payload-offloading-java-common-lib-for-aws),
|
|
172
|
+
both Apache-2.0 licensed and copyright Amazon.com, Inc. or its affiliates. AWS also publishes
|
|
173
|
+
an [official Python implementation](https://github.com/awslabs/amazon-sqs-python-extended-client-lib).
|
|
174
|
+
|
|
175
|
+
This is an independent reimplementation in Ruby. No source code from those projects is
|
|
176
|
+
included here, and the project is not affiliated with, endorsed by, or sponsored by Amazon
|
|
177
|
+
Web Services.
|
|
178
|
+
|
|
179
|
+
## License
|
|
180
|
+
|
|
181
|
+
Apache-2.0, matching the library this one follows. See [LICENSE.txt](LICENSE.txt) and
|
|
182
|
+
[NOTICE](NOTICE).
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SqsExtendedClient
|
|
4
|
+
# A drop-in wrapper around Aws::SQS::Client that offloads large message bodies
|
|
5
|
+
# to S3 and puts them back on the way out, wire compatible with the AWS Java
|
|
6
|
+
# and Python extended clients. Anything it does not override is delegated
|
|
7
|
+
# untouched to the underlying SQS client.
|
|
8
|
+
class Client
|
|
9
|
+
RESERVED_ATTRIBUTE_NAME = "ExtendedPayloadSize"
|
|
10
|
+
LEGACY_RESERVED_ATTRIBUTE_NAME = "SQSLargePayloadSize"
|
|
11
|
+
RESERVED_ATTRIBUTE_NAMES = [RESERVED_ATTRIBUTE_NAME, LEGACY_RESERVED_ATTRIBUTE_NAME].freeze
|
|
12
|
+
|
|
13
|
+
attr_reader :sqs_client, :s3_client, :config
|
|
14
|
+
|
|
15
|
+
def initialize(bucket_name:, sqs_client: nil, s3_client: nil, **options)
|
|
16
|
+
@config = Configuration.new(bucket_name: bucket_name, **options)
|
|
17
|
+
@sqs_client = sqs_client || Aws::SQS::Client.new
|
|
18
|
+
@s3_client = s3_client || Aws::S3::Client.new
|
|
19
|
+
@payload_store = PayloadStore.new(s3_client: @s3_client, config: @config)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def send_message(params = {})
|
|
23
|
+
sqs_client.send_message(**offload(params))
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def send_message_batch(params = {})
|
|
27
|
+
sqs_client.send_message_batch(**params, entries: params.fetch(:entries).map { |entry| offload(entry) })
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def receive_message(params = {})
|
|
31
|
+
params = params.merge(message_attribute_names: requested_attribute_names(params[:message_attribute_names]))
|
|
32
|
+
response = sqs_client.receive_message(**params)
|
|
33
|
+
messages = response.messages.filter_map { |message| restore(message, params.fetch(:queue_url)) }
|
|
34
|
+
Aws::SQS::Types::ReceiveMessageResult.new(messages: messages)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def delete_message(params = {})
|
|
38
|
+
receipt_handle = params.fetch(:receipt_handle)
|
|
39
|
+
cleanup_payload(receipt_handle)
|
|
40
|
+
sqs_client.delete_message(**params, receipt_handle: ReceiptHandle.strip(receipt_handle))
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def delete_message_batch(params = {})
|
|
44
|
+
entries = params.fetch(:entries).map do |entry|
|
|
45
|
+
receipt_handle = entry.fetch(:receipt_handle)
|
|
46
|
+
cleanup_payload(receipt_handle)
|
|
47
|
+
entry.merge(receipt_handle: ReceiptHandle.strip(receipt_handle))
|
|
48
|
+
end
|
|
49
|
+
sqs_client.delete_message_batch(**params, entries: entries)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def change_message_visibility(params = {})
|
|
53
|
+
sqs_client.change_message_visibility(**params, receipt_handle: ReceiptHandle.strip(params.fetch(:receipt_handle)))
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def change_message_visibility_batch(params = {})
|
|
57
|
+
entries = params.fetch(:entries).map do |entry|
|
|
58
|
+
entry.merge(receipt_handle: ReceiptHandle.strip(entry.fetch(:receipt_handle)))
|
|
59
|
+
end
|
|
60
|
+
sqs_client.change_message_visibility_batch(**params, entries: entries)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def respond_to_missing?(name, include_private = false)
|
|
64
|
+
sqs_client.respond_to?(name, include_private) || super
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def method_missing(name, ...)
|
|
68
|
+
return super unless sqs_client.respond_to?(name)
|
|
69
|
+
|
|
70
|
+
sqs_client.public_send(name, ...)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
private
|
|
74
|
+
|
|
75
|
+
# Send path: swap the body for a pointer and flag the message.
|
|
76
|
+
def offload(params)
|
|
77
|
+
attributes = params[:message_attributes] || {}
|
|
78
|
+
validate_attributes!(attributes)
|
|
79
|
+
|
|
80
|
+
body = params.fetch(:message_body)
|
|
81
|
+
return params unless config.always_through_s3? || large?(body, attributes)
|
|
82
|
+
|
|
83
|
+
pointer = @payload_store.put(body)
|
|
84
|
+
params.merge(
|
|
85
|
+
message_body: pointer.to_json,
|
|
86
|
+
message_attributes: attributes.merge(
|
|
87
|
+
reserved_attribute_name => { data_type: "Number", string_value: body.bytesize.to_s }
|
|
88
|
+
)
|
|
89
|
+
)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
# Receive path: pull the body back out of S3 and hide our bookkeeping.
|
|
93
|
+
# Returns nil for a message that was dropped, see ignore_payload_not_found.
|
|
94
|
+
def restore(message, queue_url)
|
|
95
|
+
attributes = message.message_attributes || {}
|
|
96
|
+
return message unless RESERVED_ATTRIBUTE_NAMES.any? { |name| attributes.key?(name) }
|
|
97
|
+
|
|
98
|
+
pointer = PayloadPointer.from_json(message.body)
|
|
99
|
+
begin
|
|
100
|
+
body = @payload_store.get(pointer)
|
|
101
|
+
rescue Aws::S3::Errors::NoSuchKey
|
|
102
|
+
raise unless config.ignore_payload_not_found?
|
|
103
|
+
|
|
104
|
+
sqs_client.delete_message(queue_url: queue_url, receipt_handle: message.receipt_handle)
|
|
105
|
+
return nil
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
rebuild(
|
|
109
|
+
message,
|
|
110
|
+
body: body,
|
|
111
|
+
message_attributes: attributes.except(*RESERVED_ATTRIBUTE_NAMES),
|
|
112
|
+
receipt_handle: ReceiptHandle.embed(message.receipt_handle, pointer)
|
|
113
|
+
)
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def cleanup_payload(receipt_handle)
|
|
117
|
+
return unless config.cleanup_s3_payload? && ReceiptHandle.embedded?(receipt_handle)
|
|
118
|
+
|
|
119
|
+
@payload_store.delete(ReceiptHandle.pointer(receipt_handle))
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
# Ask for the reserved attributes on top of whatever the caller wanted, so a
|
|
123
|
+
# receive that names specific attributes still tells us the body is a pointer.
|
|
124
|
+
def requested_attribute_names(names)
|
|
125
|
+
((names || []) - RESERVED_ATTRIBUTE_NAMES) + RESERVED_ATTRIBUTE_NAMES
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def reserved_attribute_name
|
|
129
|
+
config.use_legacy_reserved_attribute_name? ? LEGACY_RESERVED_ATTRIBUTE_NAME : RESERVED_ATTRIBUTE_NAME
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def large?(body, attributes)
|
|
133
|
+
body.bytesize + attributes_size(attributes) > config.payload_size_threshold
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def validate_attributes!(attributes)
|
|
137
|
+
size = attributes_size(attributes)
|
|
138
|
+
if size > config.payload_size_threshold
|
|
139
|
+
raise MessageAttributeError,
|
|
140
|
+
"message attributes total #{size} bytes, over the #{config.payload_size_threshold} byte threshold; " \
|
|
141
|
+
"put the payload in the message body instead"
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
if attributes.size > Configuration::MAX_ALLOWED_ATTRIBUTES
|
|
145
|
+
raise MessageAttributeError,
|
|
146
|
+
"#{attributes.size} message attributes exceeds the maximum of " \
|
|
147
|
+
"#{Configuration::MAX_ALLOWED_ATTRIBUTES} for large payload messages"
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
reserved = RESERVED_ATTRIBUTE_NAMES.find { |name| attributes.key?(name) }
|
|
151
|
+
return if reserved.nil?
|
|
152
|
+
|
|
153
|
+
raise MessageAttributeError, "message attribute #{reserved} is reserved by the extended client"
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
def attributes_size(attributes)
|
|
157
|
+
attributes.sum do |name, value|
|
|
158
|
+
size = name.to_s.bytesize
|
|
159
|
+
size += attribute_field(value, :data_type).to_s.bytesize
|
|
160
|
+
size += attribute_field(value, :string_value).to_s.bytesize
|
|
161
|
+
size + attribute_field(value, :binary_value).to_s.bytesize
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
# Attribute values arrive as hashes on the way out and as SDK structs on the
|
|
166
|
+
# way in; read either.
|
|
167
|
+
def attribute_field(value, name)
|
|
168
|
+
return value.public_send(name) unless value.is_a?(Hash)
|
|
169
|
+
|
|
170
|
+
value[name] || value[name.to_s]
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
# SDK response structs are rebuilt rather than mutated so nested members survive.
|
|
174
|
+
def rebuild(message, **overrides)
|
|
175
|
+
members = message.members.to_h { |member| [member, message[member]] }
|
|
176
|
+
Aws::SQS::Types::Message.new(**members, **overrides)
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
end
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SqsExtendedClient
|
|
4
|
+
class Configuration
|
|
5
|
+
# SQS caps a message at 256 KiB; anything larger goes to S3.
|
|
6
|
+
DEFAULT_PAYLOAD_SIZE_THRESHOLD = 262_144
|
|
7
|
+
|
|
8
|
+
# SQS allows 10 message attributes and the reserved one takes a slot.
|
|
9
|
+
MAX_ALLOWED_ATTRIBUTES = 9
|
|
10
|
+
|
|
11
|
+
MAX_S3_KEY_LENGTH = 1024
|
|
12
|
+
UUID_LENGTH = 36
|
|
13
|
+
MAX_S3_KEY_PREFIX_LENGTH = MAX_S3_KEY_LENGTH - UUID_LENGTH
|
|
14
|
+
INVALID_S3_KEY_PREFIX_CHARACTERS = %r{[^a-zA-Z0-9./_-]}
|
|
15
|
+
|
|
16
|
+
attr_reader :bucket_name, :s3_key_prefix, :payload_size_threshold, :s3_put_object_options, :always_through_s3,
|
|
17
|
+
:cleanup_s3_payload, :ignore_payload_not_found, :use_legacy_reserved_attribute_name
|
|
18
|
+
|
|
19
|
+
alias always_through_s3? always_through_s3
|
|
20
|
+
alias cleanup_s3_payload? cleanup_s3_payload
|
|
21
|
+
alias ignore_payload_not_found? ignore_payload_not_found
|
|
22
|
+
alias use_legacy_reserved_attribute_name? use_legacy_reserved_attribute_name
|
|
23
|
+
|
|
24
|
+
def initialize(
|
|
25
|
+
bucket_name:,
|
|
26
|
+
s3_key_prefix: "",
|
|
27
|
+
payload_size_threshold: DEFAULT_PAYLOAD_SIZE_THRESHOLD,
|
|
28
|
+
always_through_s3: false,
|
|
29
|
+
cleanup_s3_payload: true,
|
|
30
|
+
ignore_payload_not_found: false,
|
|
31
|
+
use_legacy_reserved_attribute_name: false,
|
|
32
|
+
s3_put_object_options: {}
|
|
33
|
+
)
|
|
34
|
+
raise ConfigurationError, "bucket_name is required" if bucket_name.nil? || bucket_name.to_s.empty?
|
|
35
|
+
|
|
36
|
+
@bucket_name = bucket_name
|
|
37
|
+
@s3_key_prefix = validate_key_prefix(s3_key_prefix)
|
|
38
|
+
@payload_size_threshold = Integer(payload_size_threshold)
|
|
39
|
+
@always_through_s3 = always_through_s3
|
|
40
|
+
@cleanup_s3_payload = cleanup_s3_payload
|
|
41
|
+
@ignore_payload_not_found = ignore_payload_not_found
|
|
42
|
+
@use_legacy_reserved_attribute_name = use_legacy_reserved_attribute_name
|
|
43
|
+
@s3_put_object_options = s3_put_object_options
|
|
44
|
+
freeze
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
private
|
|
48
|
+
|
|
49
|
+
def validate_key_prefix(prefix)
|
|
50
|
+
trimmed = prefix.to_s.strip
|
|
51
|
+
return trimmed if trimmed.empty?
|
|
52
|
+
|
|
53
|
+
if trimmed.length > MAX_S3_KEY_PREFIX_LENGTH
|
|
54
|
+
raise ConfigurationError, "s3_key_prefix must be at most #{MAX_S3_KEY_PREFIX_LENGTH} characters"
|
|
55
|
+
end
|
|
56
|
+
raise ConfigurationError, "s3_key_prefix must not start with '.' or '/'" if trimmed.start_with?(".", "/")
|
|
57
|
+
raise ConfigurationError, "s3_key_prefix must not contain '..'" if trimmed.include?("..")
|
|
58
|
+
if INVALID_S3_KEY_PREFIX_CHARACTERS.match?(trimmed)
|
|
59
|
+
raise ConfigurationError,
|
|
60
|
+
"s3_key_prefix may only contain letters, digits, '/', '_', '-' and '.'"
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
trimmed
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SqsExtendedClient
|
|
4
|
+
class Error < StandardError; end
|
|
5
|
+
|
|
6
|
+
# Raised when the client is built with options it cannot work with.
|
|
7
|
+
class ConfigurationError < Error; end
|
|
8
|
+
|
|
9
|
+
# Raised when a message body is flagged as offloaded but is not a valid pointer.
|
|
10
|
+
class InvalidPointerError < Error; end
|
|
11
|
+
|
|
12
|
+
# Raised when outgoing message attributes violate the extended client's limits.
|
|
13
|
+
class MessageAttributeError < Error; end
|
|
14
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "json"
|
|
4
|
+
|
|
5
|
+
module SqsExtendedClient
|
|
6
|
+
# The reference that takes the place of an offloaded message body.
|
|
7
|
+
#
|
|
8
|
+
# On the wire it is a two element JSON array whose first element is the Java
|
|
9
|
+
# class name the original implementation serialized with. We always write the
|
|
10
|
+
# current name and ignore whatever we read, which is how messages from the
|
|
11
|
+
# legacy v1 Java client stay readable.
|
|
12
|
+
class PayloadPointer
|
|
13
|
+
CLASS_NAME = "software.amazon.payloadoffloading.PayloadS3Pointer"
|
|
14
|
+
LEGACY_CLASS_NAME = "com.amazon.sqs.javamessaging.MessageS3Pointer"
|
|
15
|
+
|
|
16
|
+
attr_reader :bucket_name, :key
|
|
17
|
+
|
|
18
|
+
def initialize(bucket_name, key)
|
|
19
|
+
@bucket_name = bucket_name
|
|
20
|
+
@key = key
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def self.from_json(json)
|
|
24
|
+
parsed = JSON.parse(json)
|
|
25
|
+
unless parsed.is_a?(Array) && parsed.size == 2 && parsed[1].is_a?(Hash)
|
|
26
|
+
raise InvalidPointerError, "expected a [class_name, pointer] pair, got: #{json.inspect}"
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
body = parsed[1]
|
|
30
|
+
bucket_name = body["s3BucketName"]
|
|
31
|
+
key = body["s3Key"]
|
|
32
|
+
if bucket_name.nil? || key.nil?
|
|
33
|
+
raise InvalidPointerError,
|
|
34
|
+
"pointer is missing s3BucketName or s3Key: #{json.inspect}"
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
new(bucket_name, key)
|
|
38
|
+
rescue JSON::ParserError => e
|
|
39
|
+
raise InvalidPointerError, "message body is not valid JSON: #{e.message}"
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def to_json(*_args)
|
|
43
|
+
JSON.generate([CLASS_NAME, { "s3BucketName" => bucket_name, "s3Key" => key }])
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def ==(other)
|
|
47
|
+
other.is_a?(PayloadPointer) && other.bucket_name == bucket_name && other.key == key
|
|
48
|
+
end
|
|
49
|
+
alias eql? ==
|
|
50
|
+
|
|
51
|
+
def hash
|
|
52
|
+
[bucket_name, key].hash
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def to_s
|
|
56
|
+
"s3://#{bucket_name}/#{key}"
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "securerandom"
|
|
4
|
+
|
|
5
|
+
module SqsExtendedClient
|
|
6
|
+
# Puts, gets and deletes message bodies in S3.
|
|
7
|
+
class PayloadStore
|
|
8
|
+
def initialize(s3_client:, config:)
|
|
9
|
+
@s3_client = s3_client
|
|
10
|
+
@config = config
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def put(payload)
|
|
14
|
+
key = "#{@config.s3_key_prefix}#{SecureRandom.uuid}"
|
|
15
|
+
@s3_client.put_object(
|
|
16
|
+
**@config.s3_put_object_options,
|
|
17
|
+
bucket: @config.bucket_name,
|
|
18
|
+
key: key,
|
|
19
|
+
body: payload
|
|
20
|
+
)
|
|
21
|
+
PayloadPointer.new(@config.bucket_name, key)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def get(pointer)
|
|
25
|
+
@s3_client.get_object(bucket: pointer.bucket_name, key: pointer.key).body.read
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def delete(pointer)
|
|
29
|
+
@s3_client.delete_object(bucket: pointer.bucket_name, key: pointer.key)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SqsExtendedClient
|
|
4
|
+
# Deleting a message has to delete its S3 object too, but delete_message only
|
|
5
|
+
# carries a receipt handle. The Java client solves this by prefixing the real
|
|
6
|
+
# handle with the bucket and key between markers, and stripping them back off
|
|
7
|
+
# before the call reaches SQS. The markers below are wire format: a message
|
|
8
|
+
# received here may well be deleted by a Java or Python consumer.
|
|
9
|
+
module ReceiptHandle
|
|
10
|
+
BUCKET_MARKER = "-..s3BucketName..-"
|
|
11
|
+
KEY_MARKER = "-..s3Key..-"
|
|
12
|
+
|
|
13
|
+
module_function
|
|
14
|
+
|
|
15
|
+
def embed(receipt_handle, pointer)
|
|
16
|
+
"#{BUCKET_MARKER}#{pointer.bucket_name}#{BUCKET_MARKER}" \
|
|
17
|
+
"#{KEY_MARKER}#{pointer.key}#{KEY_MARKER}#{receipt_handle}"
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def embedded?(receipt_handle)
|
|
21
|
+
receipt_handle.include?(BUCKET_MARKER) && receipt_handle.include?(KEY_MARKER)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# The original SQS receipt handle, i.e. everything after the closing key marker.
|
|
25
|
+
def strip(receipt_handle)
|
|
26
|
+
return receipt_handle unless embedded?(receipt_handle)
|
|
27
|
+
|
|
28
|
+
closing = receipt_handle.index(KEY_MARKER, receipt_handle.index(KEY_MARKER) + KEY_MARKER.length)
|
|
29
|
+
receipt_handle[(closing + KEY_MARKER.length)..]
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def pointer(receipt_handle)
|
|
33
|
+
PayloadPointer.new(between_markers(receipt_handle, BUCKET_MARKER), between_markers(receipt_handle, KEY_MARKER))
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def between_markers(receipt_handle, marker)
|
|
37
|
+
opening = receipt_handle.index(marker)
|
|
38
|
+
closing = receipt_handle.index(marker, opening + marker.length)
|
|
39
|
+
receipt_handle[(opening + marker.length)...closing]
|
|
40
|
+
end
|
|
41
|
+
private_class_method :between_markers
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "aws-sdk-s3"
|
|
4
|
+
require "aws-sdk-sqs"
|
|
5
|
+
|
|
6
|
+
require_relative "sqs_extended_client/version"
|
|
7
|
+
require_relative "sqs_extended_client/errors"
|
|
8
|
+
require_relative "sqs_extended_client/configuration"
|
|
9
|
+
require_relative "sqs_extended_client/payload_pointer"
|
|
10
|
+
require_relative "sqs_extended_client/receipt_handle"
|
|
11
|
+
require_relative "sqs_extended_client/payload_store"
|
|
12
|
+
require_relative "sqs_extended_client/client"
|
|
13
|
+
|
|
14
|
+
module SqsExtendedClient
|
|
15
|
+
def self.new(...)
|
|
16
|
+
Client.new(...)
|
|
17
|
+
end
|
|
18
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: sqs_extended_client
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Ngoc Bui
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2026-09-18 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: aws-sdk-s3
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.0'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: aws-sdk-sqs
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '1.0'
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '1.0'
|
|
41
|
+
description: A wrapper around Aws::SQS::Client that stores large message bodies in
|
|
42
|
+
S3 and sends a pointer through the queue instead, wire compatible with the AWS SQS
|
|
43
|
+
extended client libraries for Java and Python.
|
|
44
|
+
email:
|
|
45
|
+
- ngocbui.se@gmail.com
|
|
46
|
+
executables: []
|
|
47
|
+
extensions: []
|
|
48
|
+
extra_rdoc_files: []
|
|
49
|
+
files:
|
|
50
|
+
- CHANGELOG.md
|
|
51
|
+
- LICENSE.txt
|
|
52
|
+
- NOTICE
|
|
53
|
+
- README.md
|
|
54
|
+
- lib/sqs_extended_client.rb
|
|
55
|
+
- lib/sqs_extended_client/client.rb
|
|
56
|
+
- lib/sqs_extended_client/configuration.rb
|
|
57
|
+
- lib/sqs_extended_client/errors.rb
|
|
58
|
+
- lib/sqs_extended_client/payload_pointer.rb
|
|
59
|
+
- lib/sqs_extended_client/payload_store.rb
|
|
60
|
+
- lib/sqs_extended_client/receipt_handle.rb
|
|
61
|
+
- lib/sqs_extended_client/version.rb
|
|
62
|
+
homepage: https://github.com/xuanngoc/aws-sqs-ruby-extended-client
|
|
63
|
+
licenses:
|
|
64
|
+
- Apache-2.0
|
|
65
|
+
metadata:
|
|
66
|
+
homepage_uri: https://github.com/xuanngoc/aws-sqs-ruby-extended-client
|
|
67
|
+
source_code_uri: https://github.com/xuanngoc/aws-sqs-ruby-extended-client
|
|
68
|
+
changelog_uri: https://github.com/xuanngoc/aws-sqs-ruby-extended-client/blob/main/CHANGELOG.md
|
|
69
|
+
rubygems_mfa_required: 'true'
|
|
70
|
+
post_install_message:
|
|
71
|
+
rdoc_options: []
|
|
72
|
+
require_paths:
|
|
73
|
+
- lib
|
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
75
|
+
requirements:
|
|
76
|
+
- - ">="
|
|
77
|
+
- !ruby/object:Gem::Version
|
|
78
|
+
version: '3.1'
|
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
|
+
requirements:
|
|
81
|
+
- - ">="
|
|
82
|
+
- !ruby/object:Gem::Version
|
|
83
|
+
version: '0'
|
|
84
|
+
requirements: []
|
|
85
|
+
rubygems_version: 3.4.10
|
|
86
|
+
signing_key:
|
|
87
|
+
specification_version: 4
|
|
88
|
+
summary: Send and receive SQS messages larger than 256 KB by offloading the payload
|
|
89
|
+
to S3.
|
|
90
|
+
test_files: []
|