Class: HermesMessengerOfTheGods::Endpoints::Sns
- Defined in:
- lib/hermes_messenger_of_the_gods/endpoints/sns.rb
Constant Summary
Constants inherited from Base
Base::DEFAULT_OPTIONS, Base::DEFAULT_RETRYS
Instance Attribute Summary
Attributes inherited from Base
#endpoint, #errors, #name, #options, #result
Instance Method Summary collapse
- #bulk_transmit(payloads) ⇒ Object
- #sns_client ⇒ Object
- #to_transmit_payload(message, raw_message, dispatch_options = {}) ⇒ Object
- #transmit(payload) ⇒ Object
Methods inherited from Base
#_transmit_payload, #backoff, #bulk_dispatch!, #dispatch, #dispatch!, #fetch_option, #handle_failure, #handle_success, #initialize, #max_retries, #retry_from, #teardown, #transform_message
Constructor Details
This class inherits a constructor from HermesMessengerOfTheGods::Endpoints::Base
Instance Method Details
#bulk_transmit(payloads) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/hermes_messenger_of_the_gods/endpoints/sns.rb', line 25 def bulk_transmit(payloads) # Batch Publish requires a message id, so we'll generate one if it's not set all_publish_batch_request_entries = payloads.map do |payload| {id: SecureRandom.uuid}.merge(payload) end failed_msgs = [] all_publish_batch_request_entries.each_slice(10) do |publish_batch_request_entries| resp = sns_client.publish_batch(topic_arn: endpoint, publish_batch_request_entries: publish_batch_request_entries) failed_msgs.concat(resp.failed) end if failed_msgs.any? all_sender_fault = failed_msgs.all?(&:sender_fault) raise FatalError, "Error in dispatching: #{failed_msgs[0].}" if all_sender_fault raise "Some messages failed to send due to recoverable error #{failed_msgs[0].}" end true end |
#sns_client ⇒ Object
9 10 11 |
# File 'lib/hermes_messenger_of_the_gods/endpoints/sns.rb', line 9 def sns_client HermesMessengerOfTheGods.configuration.sns_client end |
#to_transmit_payload(message, raw_message, dispatch_options = {}) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/hermes_messenger_of_the_gods/endpoints/sns.rb', line 13 def to_transmit_payload(, , = {}) pub_opts = fetch_option(:publish_options, ) || {} = JSON.dump() if [:jsonify] pub_opts.merge(, message: ) end |
#transmit(payload) ⇒ Object
21 22 23 |
# File 'lib/hermes_messenger_of_the_gods/endpoints/sns.rb', line 21 def transmit(payload) bulk_transmit([payload]) end |