Amazon SQS でのすべてのキューに関する情報の取得 - AWS SDK for Ruby

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

Amazon SQS でのすべてのキューに関する情報の取得

次の例では、us-west-2 リージョンで、Amazon SQS キューの URL、ARN、利用可能なメッセージ、および処理中のメッセージを一覧表示します。

# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 require 'aws-sdk-sqs' require 'aws-sdk-sts' # Lists the URLs of available queues in Amazon Simple Queue Service (Amazon SQS). # # @param sqs_client [Aws::SQS::Client] An initialized Amazon SQS client. # @example # list_queue_urls(Aws::SQS::Client.new(region: 'us-east-1')) def list_queue_urls(sqs_client) queues = sqs_client.list_queues queues.queue_urls.each do |url| puts url end rescue StandardError => e puts "Error listing queue URLs: #{e.message}" end # Lists the attributes of a queue in Amazon Simple Queue Service (Amazon SQS). # # @param sqs_client [Aws::SQS::Client] An initialized Amazon SQS client. # @param queue_url [String] The URL of the queue. # @example # list_queue_attributes( # Aws::SQS::Client.new(region: 'us-east-1'), # 'https://sqs.us-east-1.amazonaws.com/111111111111/my-queue' # ) def list_queue_attributes(sqs_client, queue_url) attributes = sqs_client.get_queue_attributes( queue_url: queue_url, attribute_names: [ "All" ] ) attributes.attributes.each do |key, value| puts "#{key}: #{value}" end rescue StandardError => e puts "Error getting queue attributes: #{e.message}" end # Full example call: def run_me region = 'us-east-1' queue_name = 'my-queue' sqs_client = Aws::SQS::Client.new(region: region) puts 'Listing available queue URLs...' list_queue_urls(sqs_client) sts_client = Aws::STS::Client.new(region: region) # For example: # 'https://sqs.us-east-1.amazonaws.com/111111111111/my-queue' queue_url = 'https://sqs.' + region + '.amazonaws.com/' + sts_client.get_caller_identity.account + '/' + queue_name puts "\nGetting information about queue '#{queue_name}'..." list_queue_attributes(sqs_client, queue_url) end run_me if $PROGRAM_NAME == __FILE__