Class: DbBlaster::SnsPublisher

Inherits:
BasePublisher show all
Defined in:
lib/db_blaster/sns_publisher.rb

Overview

Publishes records to AWS SNS

Instance Attribute Summary

Attributes inherited from BasePublisher

#batch_start_time, #records, #source_table

Instance Method Summary collapse

Methods inherited from BasePublisher

#initialize, publish

Constructor Details

This class inherits a constructor from DbBlaster::BasePublisher

Instance Method Details

#clientObject



23
24
25
26
27
# File 'lib/db_blaster/sns_publisher.rb', line 23

def client
  @client ||= Aws::SNS::Client.new(region: DbBlaster.configuration.aws_region,
                                   credentials: Aws::Credentials.new(DbBlaster.configuration.aws_access_key,
                                                                     DbBlaster.configuration.aws_access_secret))
end

#message_attributesObject



29
30
31
32
# File 'lib/db_blaster/sns_publisher.rb', line 29

def message_attributes
  (DbBlaster.configuration.extra_sns_message_attributes || {})
    .merge('source_table' => { data_type: 'String', string_value: source_table.name })
end

#publishObject



10
11
12
13
# File 'lib/db_blaster/sns_publisher.rb', line 10

def publish
  topic.publish(message_attributes: message_attributes,
                message: records.to_json)
end

#resourceObject



19
20
21
# File 'lib/db_blaster/sns_publisher.rb', line 19

def resource
  @resource ||= Aws::SNS::Resource.new(client: client)
end

#topicObject



15
16
17
# File 'lib/db_blaster/sns_publisher.rb', line 15

def topic
  resource.topic(DbBlaster.configuration.sns_topic)
end