aws-sdk-sqs 1.60.0 → 1.93.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 +4 -4
- data/CHANGELOG.md +165 -0
- data/VERSION +1 -1
- data/lib/aws-sdk-sqs/client.rb +393 -175
- data/lib/aws-sdk-sqs/client_api.rb +255 -58
- data/lib/aws-sdk-sqs/customizations.rb +5 -1
- data/lib/aws-sdk-sqs/endpoint_parameters.rb +9 -6
- data/lib/aws-sdk-sqs/endpoint_provider.rb +16 -20
- data/lib/aws-sdk-sqs/endpoints.rb +2 -320
- data/lib/aws-sdk-sqs/errors.rb +251 -0
- data/lib/aws-sdk-sqs/message.rb +3 -3
- data/lib/aws-sdk-sqs/plugins/endpoints.rb +23 -60
- data/lib/aws-sdk-sqs/plugins/md5s.rb +84 -35
- data/lib/aws-sdk-sqs/queue.rb +106 -31
- data/lib/aws-sdk-sqs/queue_poller.rb +66 -36
- data/lib/aws-sdk-sqs/resource.rb +10 -13
- data/lib/aws-sdk-sqs/types.rb +418 -55
- data/lib/aws-sdk-sqs.rb +17 -13
- data/sig/client.rbs +369 -0
- data/sig/errors.rbs +98 -0
- data/sig/message.rbs +73 -0
- data/sig/queue.rbs +164 -0
- data/sig/resource.rbs +110 -0
- data/sig/types.rbs +472 -0
- data/sig/waiters.rbs +13 -0
- metadata +18 -11
@@ -4,7 +4,6 @@ require 'set'
|
|
4
4
|
|
5
5
|
module Aws
|
6
6
|
module SQS
|
7
|
-
|
8
7
|
# A utility class for long polling messages in a loop. **Messages are
|
9
8
|
# automatically deleted from the queue at the end of the given block.**
|
10
9
|
#
|
@@ -135,7 +134,7 @@ module Aws
|
|
135
134
|
# ### `:idle_timeout` Option
|
136
135
|
#
|
137
136
|
# This is a configurable, maximum number of seconds to wait for a
|
138
|
-
# new message before the polling loop
|
137
|
+
# new message before the polling loop exits. By default, there is
|
139
138
|
# no idle timeout.
|
140
139
|
#
|
141
140
|
# # stops polling after a minute of no received messages
|
@@ -181,6 +180,16 @@ module Aws
|
|
181
180
|
# end
|
182
181
|
# ```
|
183
182
|
#
|
183
|
+
# * Configure an {#after_empty_receive} callback.
|
184
|
+
#
|
185
|
+
# ```
|
186
|
+
# poller.after_empty_receive do |stats|
|
187
|
+
# logger.info("requests: #{stats.request_count}")
|
188
|
+
# logger.info("messages: #{stats.received_message_count}")
|
189
|
+
# logger.info("last-timestamp: #{stats.last_message_received_at}")
|
190
|
+
# end
|
191
|
+
# ```
|
192
|
+
#
|
184
193
|
# * Accept a 2nd argument in the poll block, for example:
|
185
194
|
#
|
186
195
|
# ```
|
@@ -203,7 +212,6 @@ module Aws
|
|
203
212
|
# ```
|
204
213
|
#
|
205
214
|
class QueuePoller
|
206
|
-
|
207
215
|
# @param [String] queue_url
|
208
216
|
# @option options [Client] :client
|
209
217
|
# @option (see #poll)
|
@@ -258,6 +266,21 @@ module Aws
|
|
258
266
|
@default_config = @default_config.with(before_request: block) if block_given?
|
259
267
|
end
|
260
268
|
|
269
|
+
# Registers a callback that is invoked when the poll requests returns with no messages.
|
270
|
+
# This callback is invoked after the idle timeout is checked.
|
271
|
+
#
|
272
|
+
# poller.after_empty_receive do |stats|
|
273
|
+
# # Handle empty receive
|
274
|
+
# end
|
275
|
+
#
|
276
|
+
# @yieldparam [PollerStats] stats An object that tracks a few
|
277
|
+
# client-side statistics about the queue polling.
|
278
|
+
#
|
279
|
+
# @return [void]
|
280
|
+
def after_empty_receive(&block)
|
281
|
+
@default_config = @default_config.with(after_empty_receive: block) if block_given?
|
282
|
+
end
|
283
|
+
|
261
284
|
# Polls the queue, yielded a message, or an array of messages.
|
262
285
|
# Messages are automatically deleted from the queue at the
|
263
286
|
# end of the given block. See the class documentation on
|
@@ -333,7 +356,8 @@ module Aws
|
|
333
356
|
loop do
|
334
357
|
messages = get_messages(config, stats)
|
335
358
|
if messages.empty?
|
336
|
-
check_idle_timeout(config, stats
|
359
|
+
check_idle_timeout(config, stats)
|
360
|
+
config.after_empty_receive&.call(stats)
|
337
361
|
else
|
338
362
|
process_messages(config, stats, messages, &block)
|
339
363
|
end
|
@@ -348,21 +372,21 @@ module Aws
|
|
348
372
|
# `#receipt_handle`.
|
349
373
|
# @param [Integer] seconds
|
350
374
|
def change_message_visibility_timeout(message, seconds)
|
351
|
-
@client.change_message_visibility(
|
375
|
+
@client.change_message_visibility(
|
352
376
|
queue_url: @queue_url,
|
353
377
|
receipt_handle: message.receipt_handle,
|
354
|
-
visibility_timeout: seconds
|
355
|
-
|
378
|
+
visibility_timeout: seconds
|
379
|
+
)
|
356
380
|
end
|
357
381
|
|
358
382
|
# @note This method should be called from inside a {#poll} block.
|
359
383
|
# @param [#receipt_handle] message An object that responds to
|
360
384
|
# `#receipt_handle`.
|
361
385
|
def delete_message(message)
|
362
|
-
@client.delete_message(
|
386
|
+
@client.delete_message(
|
363
387
|
queue_url: @queue_url,
|
364
|
-
receipt_handle: message.receipt_handle
|
365
|
-
|
388
|
+
receipt_handle: message.receipt_handle
|
389
|
+
)
|
366
390
|
end
|
367
391
|
|
368
392
|
# @note This method should be called from inside a {#poll} block.
|
@@ -372,16 +396,16 @@ module Aws
|
|
372
396
|
def delete_messages(messages)
|
373
397
|
@client.delete_message_batch(
|
374
398
|
queue_url: @queue_url,
|
375
|
-
entries: messages.map
|
399
|
+
entries: messages.map do |msg|
|
376
400
|
{ id: msg.message_id, receipt_handle: msg.receipt_handle }
|
377
|
-
|
401
|
+
end
|
378
402
|
)
|
379
403
|
end
|
380
404
|
|
381
405
|
private
|
382
406
|
|
383
407
|
def get_messages(config, stats)
|
384
|
-
config.before_request
|
408
|
+
config.before_request&.call(stats)
|
385
409
|
messages = send_request(config).messages
|
386
410
|
stats.request_count += 1
|
387
411
|
messages
|
@@ -392,17 +416,22 @@ module Aws
|
|
392
416
|
@client.receive_message(params)
|
393
417
|
end
|
394
418
|
|
395
|
-
def check_idle_timeout(config, stats
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
419
|
+
def check_idle_timeout(config, stats)
|
420
|
+
return unless config.idle_timeout
|
421
|
+
|
422
|
+
since = stats.last_message_received_at || stats.polling_started_at
|
423
|
+
idle_time = Time.now - since
|
424
|
+
throw :stop_polling if idle_time > config.idle_timeout
|
401
425
|
end
|
402
426
|
|
403
427
|
def process_messages(config, stats, messages, &block)
|
404
428
|
stats.received_message_count += messages.count
|
405
429
|
stats.last_message_received_at = Time.now
|
430
|
+
|
431
|
+
# duplicated messages will have a different receipt handle
|
432
|
+
# so we need to provide the most recent receipt to
|
433
|
+
# delete a batch - thus, filtering below by message_id
|
434
|
+
messages = messages.reverse.uniq(&:message_id).reverse!
|
406
435
|
catch(:skip_delete) do
|
407
436
|
yield_messages(config, messages, stats, &block)
|
408
437
|
delete_messages(messages) unless config.skip_delete
|
@@ -421,7 +450,6 @@ module Aws
|
|
421
450
|
|
422
451
|
# Statistics tracked client-side by the {QueuePoller}.
|
423
452
|
class PollerStats
|
424
|
-
|
425
453
|
def initialize
|
426
454
|
@request_count = 0
|
427
455
|
@received_message_count = 0
|
@@ -444,27 +472,26 @@ module Aws
|
|
444
472
|
|
445
473
|
# @return [Time,nil]
|
446
474
|
attr_accessor :polling_stopped_at
|
447
|
-
|
448
475
|
end
|
449
476
|
|
450
477
|
# A read-only set of configuration used by the QueuePoller.
|
451
478
|
class PollerConfig
|
452
|
-
|
453
479
|
# @api private
|
454
|
-
CONFIG_OPTIONS = Set.new
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
480
|
+
CONFIG_OPTIONS = Set.new %i[
|
481
|
+
idle_timeout
|
482
|
+
skip_delete
|
483
|
+
before_request
|
484
|
+
after_empty_receive
|
485
|
+
]
|
459
486
|
|
460
487
|
# @api private
|
461
|
-
PARAM_OPTIONS = Set.new
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
]
|
488
|
+
PARAM_OPTIONS = Set.new %i[
|
489
|
+
wait_time_seconds
|
490
|
+
max_number_of_messages
|
491
|
+
visibility_timeout
|
492
|
+
attribute_names
|
493
|
+
message_attribute_names
|
494
|
+
]
|
468
495
|
|
469
496
|
# @return [Integer,nil]
|
470
497
|
attr_reader :idle_timeout
|
@@ -475,6 +502,9 @@ module Aws
|
|
475
502
|
# @return [Proc,nil]
|
476
503
|
attr_reader :before_request
|
477
504
|
|
505
|
+
# @return [Proc,nil]
|
506
|
+
attr_reader :after_empty_receive
|
507
|
+
|
478
508
|
# @return [Hash]
|
479
509
|
attr_reader :request_params
|
480
510
|
|
@@ -482,12 +512,13 @@ module Aws
|
|
482
512
|
@idle_timeout = nil
|
483
513
|
@skip_delete = false
|
484
514
|
@before_request = nil
|
515
|
+
@after_empty_receive = nil
|
485
516
|
@request_params = {
|
486
517
|
wait_time_seconds: 20,
|
487
518
|
max_number_of_messages: 1,
|
488
519
|
visibility_timeout: nil,
|
489
520
|
attribute_names: ['All'],
|
490
|
-
message_attribute_names: ['All']
|
521
|
+
message_attribute_names: ['All']
|
491
522
|
}
|
492
523
|
options.each do |opt_name, value|
|
493
524
|
if CONFIG_OPTIONS.include?(opt_name)
|
@@ -522,7 +553,6 @@ module Aws
|
|
522
553
|
PARAM_OPTIONS.each { |key| hash[key] = @request_params[key] }
|
523
554
|
hash
|
524
555
|
end
|
525
|
-
|
526
556
|
end
|
527
557
|
end
|
528
558
|
end
|
data/lib/aws-sdk-sqs/resource.rb
CHANGED
@@ -112,7 +112,6 @@ module Aws::SQS
|
|
112
112
|
# Default: 10. When the `ReceiveCount` for a message exceeds the
|
113
113
|
# `maxReceiveCount` for a queue, Amazon SQS moves the message to the
|
114
114
|
# dead-letter-queue.
|
115
|
-
#
|
116
115
|
# * `RedriveAllowPolicy` – The string that includes the parameters for
|
117
116
|
# the permissions for the dead-letter queue redrive permission and
|
118
117
|
# which source queues can specify dead-letter queues as a JSON object.
|
@@ -131,7 +130,6 @@ module Aws::SQS
|
|
131
130
|
#
|
132
131
|
# * `byQueue` – Only queues specified by the `sourceQueueArns`
|
133
132
|
# parameter can specify this queue as the dead-letter queue.
|
134
|
-
#
|
135
133
|
# * `sourceQueueArns` – The Amazon Resource Names (ARN)s of the source
|
136
134
|
# queues that can specify this queue as the dead-letter queue and
|
137
135
|
# redrive messages. You can specify this parameter only when the
|
@@ -203,7 +201,6 @@ module Aws::SQS
|
|
203
201
|
#
|
204
202
|
# * If the queue has `ContentBasedDeduplication` set, your
|
205
203
|
# `MessageDeduplicationId` overrides the generated one.
|
206
|
-
#
|
207
204
|
# * When `ContentBasedDeduplication` is in effect, messages with
|
208
205
|
# identical content sent within the deduplication interval are
|
209
206
|
# treated as duplicates and only one copy of the message is
|
@@ -294,7 +291,7 @@ module Aws::SQS
|
|
294
291
|
# [3]: https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-customer-managed-policy-examples.html#grant-cross-account-permissions-to-role-and-user-name
|
295
292
|
# @return [Queue]
|
296
293
|
def create_queue(options = {})
|
297
|
-
resp = Aws::Plugins::UserAgent.
|
294
|
+
resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
|
298
295
|
@client.create_queue(options)
|
299
296
|
end
|
300
297
|
Queue.new(
|
@@ -311,17 +308,17 @@ module Aws::SQS
|
|
311
308
|
# })
|
312
309
|
# @param [Hash] options ({})
|
313
310
|
# @option options [required, String] :queue_name
|
314
|
-
# The name of the queue
|
315
|
-
#
|
316
|
-
# underscores (
|
317
|
-
#
|
318
|
-
# Queue URLs and names are case-sensitive.
|
311
|
+
# (Required) The name of the queue for which you want to fetch the URL.
|
312
|
+
# The name can be up to 80 characters long and can include alphanumeric
|
313
|
+
# characters, hyphens (-), and underscores (\_). Queue URLs and names
|
314
|
+
# are case-sensitive.
|
319
315
|
# @option options [String] :queue_owner_aws_account_id
|
320
|
-
# The Amazon Web Services account ID of the account that
|
321
|
-
# queue.
|
316
|
+
# (Optional) The Amazon Web Services account ID of the account that
|
317
|
+
# created the queue. This is only required when you are attempting to
|
318
|
+
# access a queue owned by another Amazon Web Services account.
|
322
319
|
# @return [Queue]
|
323
320
|
def get_queue_by_name(options = {})
|
324
|
-
resp = Aws::Plugins::UserAgent.
|
321
|
+
resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
|
325
322
|
@client.get_queue_url(options)
|
326
323
|
end
|
327
324
|
Queue.new(
|
@@ -355,7 +352,7 @@ module Aws::SQS
|
|
355
352
|
# @return [Queue::Collection]
|
356
353
|
def queues(options = {})
|
357
354
|
batches = Enumerator.new do |y|
|
358
|
-
resp = Aws::Plugins::UserAgent.
|
355
|
+
resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
|
359
356
|
@client.list_queues(options)
|
360
357
|
end
|
361
358
|
resp.each_page do |page|
|