Class: Ons::Producer
- Inherits:
-
Object
- Object
- Ons::Producer
- Defined in:
- lib/ons/producer.rb
Overview
the ONS Producer
Class Method Summary collapse
-
.instances ⇒ <Producer>
Get all the Producer instances.
Instance Method Summary collapse
-
#initialize(access_key, secret_key, producer_id, options = {}) ⇒ Producer
constructor
Create a new aliyun ONS Producer instance.
-
#send_message(topic, tag, body, key = '') ⇒ String
Send a message.
-
#send_timer_message(topic, tag, body, timer, key = '') ⇒ String
Send a timer message.
-
#shutdown ⇒ void
Shutdown the Producer instance.
-
#start ⇒ self
Start the Producer instance.
Constructor Details
#initialize(access_key, secret_key, producer_id, options = {}) ⇒ Producer
Create a new aliyun ONS Producer instance.
20 21 22 23 24 25 |
# File 'lib/ons/producer.rb', line 20 def initialize(access_key, secret_key, producer_id, = {}) @producer = Internal::Producer.new(access_key, secret_key, producer_id, ) # register instance self.class.instances << self end |
Class Method Details
.instances ⇒ <Producer>
Get all the Producer instances.
7 8 9 |
# File 'lib/ons/producer.rb', line 7 def self.instances @instances ||= [] end |
Instance Method Details
#send_message(topic, tag, body, key = '') ⇒ String
Send a message.
39 40 41 |
# File 'lib/ons/producer.rb', line 39 def (topic, tag, body, key = '') @producer.(topic, tag, body, key) end |
#send_timer_message(topic, tag, body, timer, key = '') ⇒ String
Send a timer message.
56 57 58 |
# File 'lib/ons/producer.rb', line 56 def (topic, tag, body, timer, key = '') @producer.(topic, tag, body, timer.to_i * 1000, key) end |
#shutdown ⇒ void
Note:
this method should be called before program exit, otherwise it would case a memory leak.
This method returns an undefined value.
Shutdown the Producer instance
Please see also Ons.register_cleanup_hooks if you want call it automatically.
76 77 78 |
# File 'lib/ons/producer.rb', line 76 def shutdown @producer.shutdown end |
#start ⇒ self
Note:
this method should be called before send any message.
Start the Producer instance.
65 66 67 68 |
# File 'lib/ons/producer.rb', line 65 def start @producer.start self end |