Class: Propono::Publisher

Inherits:
Object
  • Object
show all
Defined in:
lib/propono/services/publisher.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(aws_client, propono_config, topic_name, message, async: false, id: nil) ⇒ Publisher

Returns a new instance of Publisher.

Raises:



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/propono/services/publisher.rb', line 14

def initialize(aws_client, propono_config, topic_name, message, async: false, id: nil)
  raise PublisherError.new("Topic is nil") if topic_name.nil?
  raise PublisherError.new("Message is nil") if message.nil?

  @aws_client = aws_client
  @propono_config = propono_config
  @topic_name = topic_name
  @message = message
  @async = async

  random_id = SecureRandom.hex(3)
  @id = id ? "#{id}-#{random_id}" : random_id
end

Instance Attribute Details

#asyncObject (readonly)

Returns the value of attribute async.



12
13
14
# File 'lib/propono/services/publisher.rb', line 12

def async
  @async
end

#aws_clientObject (readonly)

Returns the value of attribute aws_client.



12
13
14
# File 'lib/propono/services/publisher.rb', line 12

def aws_client
  @aws_client
end

#idObject (readonly)

Returns the value of attribute id.



12
13
14
# File 'lib/propono/services/publisher.rb', line 12

def id
  @id
end

#messageObject (readonly)

Returns the value of attribute message.



12
13
14
# File 'lib/propono/services/publisher.rb', line 12

def message
  @message
end

#propono_configObject (readonly)

Returns the value of attribute propono_config.



12
13
14
# File 'lib/propono/services/publisher.rb', line 12

def propono_config
  @propono_config
end

#topic_nameObject (readonly)

Returns the value of attribute topic_name.



12
13
14
# File 'lib/propono/services/publisher.rb', line 12

def topic_name
  @topic_name
end

Class Method Details

.publish(*args) ⇒ Object



8
9
10
# File 'lib/propono/services/publisher.rb', line 8

def self.publish(*args)
  new(*args).publish
end

Instance Method Details

#publishObject



28
29
30
31
# File 'lib/propono/services/publisher.rb', line 28

def publish
  propono_config.logger.info "Propono [#{id}]: Publishing #{message} to #{topic_name}"
  async ? publish_asyncronously : publish_syncronously
end