Class | AWS::SNS::Topic |
In: |
lib/aws/sns/topic.rb
|
Parent: | Object |
arn | [R] | @return [String] The topic ARN. |
Verifies an endpoint owner‘s intent to receive messages by validating the token sent to the endpoint by an earlier Subscribe action. If the token is valid, the action creates a new subscription.
@param [String] token Short-lived token sent to an endpoint
during the {#subscribe} action.
@param [Hash] options Additional options for confirming the
subscription.
@option options [Boolean] :authenticate_on_unsubscribe
Indicates that you want to disable unauthenticated unsubsciption of the subscription.
@return [Subscription] The newly created subscription.
@return [String] Returns the human-readable name used in
the "From" field for notifications to email and email-json endpoints. If you have not set the display name the topic {#name} will be used/returned instead.
@param [String] display_name Sets the human-readable name used in
the "From" field for notifications to email and email-json endpoints.
@return [String] Returns the display_name as passed.
@return [String<JSON>] The effective delivery policy JSON string.
into account system defaults.
The topic name.
If you have not set a display name (see {display_name=}) then this is used as the "From" field for notifications to email and email-json endpoints. @return [String] Returns the toipc name.
Publishes a message to this SNS topic.
topic.publish('a short message')
You can pass a subject that is used when sending the message to email endpoints:
topic.publish('message', :subject => 'SNS message subject')
If you would like to pass a different message to various protocols (endpoint types) you can pass those as options:
topic.publish('default message', :http => "message sent to http endpoints", :https => "message sent to https endpoints", :email => "message sent to email endpoints")
The full list of acceptable protocols are listed below. The default message is sent to endpoints who‘s protocol was not listed.
@param [String] default_message The message you want to send to the
topic. Messages must be UTF-8 encoded strings at most 8 KB in size (8192 bytes, not 8192 characters).
@param [Hash] options @option options [String] :subject Used as the "Subject" line when
the message is delivered to email endpoints. Will also be included in the standard JSON messages delivered to other endpoints. * must be ASCII text that begins with a letter, number or punctuation mark * must not include line breaks or control characters * and must be less than 100 characters long
@option options [String] :http - Message to use when sending to an
HTTP endpoint.
@option options [String] :https - Message to use when sending to an
HTTPS endpoint.
@option options [String] :email - Message to use when sending to an
email endpoint.
@option options [String] :email_json - Message to use when sending
to an email json endpoint.
@option options [String] :sqs - Message to use when sending to an
SQS endpoint.
@return [String] Returns the ID of the message that was sent.
Causes the given `endpoint` to receive messages published to this topic.
## Subscribing to SQS Queues
If you subscribe to an SQS queue (with a {SQS::Queue} object} then a policy will be added/updated to the queue that will permit this topic to send it messages. Some important notes:
topic.subscribe(queue.arn) topic.subscribe(queue, :update_policy => false)
@example Using a url string to set the endpoint (http and https)
topic.subscribe('http://example.com/messages') topic.subscribe('https://example.com/messages')
@example Using a uri object to set the endpoint (http and https)
topic.subscribe(URI.parse('http://example.com/messages')) topic.subscribe(URI.parse('https://example.com/messages'))
@example Email address as endpoint
topic.subscribe('nobody@example.com')
@example Email address as a JSON endpoint
# send messages encoded as json object to the given email address topic.subscribe('nobody@example.com', :json => true)
@example SQS Queue (by arn)
# you must manage the queue policy yourself to allow the # the topic to send messages (policy action 'sqs:SendMessage') topic.subscribe('arn:aws:sqs:us-west-2:123456789123:AQueue')
@example SQS Queue (by Queue object)
# the queue policy will be added/updated to allow the topic # to send it messages topic.subscribe(AWS::SQS.new.queues.first)
@param [mixed] endpoint The endpoint that should receive
messages that are published to this topic. Valid values for `endpoint` include: * URI object * http and https URI strings * email address * {SQS::Queue} * SQS queue ARN * phone number of an SMS-enabled device
@param [Hash] options @option options [Boolean] :json (false) @return [Subscription,nil] Returns a subscription when possible.
If the subscription requires confirmation first, then `nil` is returned instead.
@return [TopicSubscriptionCollection] Returns a collection that
represents all of the subscriptions for this topic.
@return [Hash] Returns a hash of attributes about this topic,
including: * `:arn` * `:name` * `:owner` * `:display_name` * `:policy` * `:num_subscriptions_confirmed` * `:num_subscriptions_pending` * `:num_subscriptions_deleted`