Class: Propono::Client
- Inherits:
-
Object
- Object
- Propono::Client
- Defined in:
- lib/propono/components/client.rb
Instance Attribute Summary collapse
-
#aws_client ⇒ Object
readonly
Propono configuration.
-
#config ⇒ Object
readonly
Propono configuration.
Instance Method Summary collapse
- #configure {|config| ... } ⇒ Object
-
#drain_queue(topic, &message_processor) ⇒ Object
Listens on a queue and yields for each message.
-
#initialize(settings = {}, &block) ⇒ Client
constructor
A new instance of Client.
-
#listen(topic_name, options = {}, &message_processor) ⇒ Object
Listens on a queue and yields for each message.
-
#publish(topic, message, options = {}) ⇒ Object
Publishes a new message into the Propono pub/sub network.
-
#subscribe(topic) ⇒ Object
Creates a new SNS-SQS subscription on the specified topic.
Constructor Details
#initialize(settings = {}, &block) ⇒ Client
Returns a new instance of Client.
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/propono/components/client.rb', line 28 def initialize(settings = {}, &block) @config = Configuration.new if block_given? configure(&block) else settings.each do |key, value| config.send("#{key}=", value) end end @aws_client = AwsClient.new(AwsConfig.new(config)) end |
Instance Attribute Details
#aws_client ⇒ Object (readonly)
Propono configuration.
Settings should be set in an initializer or using some other method that ensures they are set before any Propono code is used.
They can be set in one of the following ways:
-
As options passed to
new
as a hash.
Propono::Client.new(application_name: 'my-application')
-
As options passed to
new
using a block.
Propono::Client.new do |config"
config.application_name: 'my-application'
end
-
By calling the
Propono::Client#configure
.
client.configure do |config|
config.access_key = "my-access-key"
end
27 28 29 |
# File 'lib/propono/components/client.rb', line 27 def aws_client @aws_client end |
#config ⇒ Object (readonly)
Propono configuration.
Settings should be set in an initializer or using some other method that ensures they are set before any Propono code is used.
They can be set in one of the following ways:
-
As options passed to
new
as a hash.
Propono::Client.new(application_name: 'my-application')
-
As options passed to
new
using a block.
Propono::Client.new do |config"
config.application_name: 'my-application'
end
-
By calling the
Propono::Client#configure
.
client.configure do |config|
config.access_key = "my-access-key"
end
27 28 29 |
# File 'lib/propono/components/client.rb', line 27 def config @config end |
Instance Method Details
#configure {|config| ... } ⇒ Object
41 42 43 |
# File 'lib/propono/components/client.rb', line 41 def configure yield config end |
#drain_queue(topic, &message_processor) ⇒ Object
Listens on a queue and yields for each message
Calling this will enter a queue-listening loop that yields the message_processor for each messages. The loop will end when all messages have been processed.
This method will automatically create a subscription if one does not exist, so there is no need to call subscribe
in addition.
93 94 95 |
# File 'lib/propono/components/client.rb', line 93 def drain_queue(topic, &) QueueListener.drain(aws_client, config, topic, &) end |
#listen(topic_name, options = {}, &message_processor) ⇒ Object
Listens on a queue and yields for each message
Calling this will enter a queue-listening loop that yields the message_processor for each messages.
This method will automatically create a subscription if one does not exist, so there is no need to call subscribe
in addition.
77 78 79 |
# File 'lib/propono/components/client.rb', line 77 def listen(topic_name, = {}, &) QueueListener.listen(aws_client, config, topic_name, , &) end |
#publish(topic, message, options = {}) ⇒ Object
Publishes a new message into the Propono pub/sub network.
This requires a topic and a message. By default this pushes out AWS SNS.
52 53 54 55 |
# File 'lib/propono/components/client.rb', line 52 def publish(topic, , = {}) suffixed_topic = "#{topic}#{config.queue_suffix}" Publisher.publish(aws_client, config, suffixed_topic, , ) end |
#subscribe(topic) ⇒ Object
Creates a new SNS-SQS subscription on the specified topic.
This is implicitly called by #listen.
62 63 64 |
# File 'lib/propono/components/client.rb', line 62 def subscribe(topic) QueueSubscription.create(aws_client, config, topic) end |