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 settings.
-
#config ⇒ Object
readonly
Propono configuration settings.
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.
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/propono/components/client.rb', line 23 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.
Settings should be set in an initializer or using some other method that insures they are set before any Propono code is used. They can be set as followed:
Propono.config.access_key = "my-access-key"
The following settings are allowed:
-
:access_key
- The AWS access key -
:secret_key
- The AWS secret key -
:queue_region
- The AWS region -
:application_name
- The name of the application Propono is included in. -
:queue_suffix
- Optional string to append to topic and queue names. -
:logger
- A logger object that responds to puts.
22 23 24 |
# File 'lib/propono/components/client.rb', line 22 def aws_client @aws_client end |
#config ⇒ Object (readonly)
Propono configuration settings.
Settings should be set in an initializer or using some other method that insures they are set before any Propono code is used. They can be set as followed:
Propono.config.access_key = "my-access-key"
The following settings are allowed:
-
:access_key
- The AWS access key -
:secret_key
- The AWS secret key -
:queue_region
- The AWS region -
:application_name
- The name of the application Propono is included in. -
:queue_suffix
- Optional string to append to topic and queue names. -
:logger
- A logger object that responds to puts.
22 23 24 |
# File 'lib/propono/components/client.rb', line 22 def config @config end |
Instance Method Details
#configure {|config| ... } ⇒ Object
36 37 38 |
# File 'lib/propono/components/client.rb', line 36 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.
88 89 90 |
# File 'lib/propono/components/client.rb', line 88 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.
72 73 74 |
# File 'lib/propono/components/client.rb', line 72 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.
47 48 49 50 |
# File 'lib/propono/components/client.rb', line 47 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.
57 58 59 |
# File 'lib/propono/components/client.rb', line 57 def subscribe(topic) QueueSubscription.create(aws_client, config, topic) end |