Class: ActivePubsub::Publisher
- Inherits:
-
Object
- Object
- ActivePubsub::Publisher
- Includes:
- Celluloid
- Defined in:
- lib/active_pubsub/publisher.rb
Class Attribute Summary collapse
-
.publishable_model_count ⇒ Object
Returns the value of attribute publishable_model_count.
-
.started ⇒ Object
Returns the value of attribute started.
Instance Attribute Summary collapse
-
#connection ⇒ Object
Returns the value of attribute connection.
Class Method Summary collapse
Instance Method Summary collapse
- #channel ⇒ Object
- #clear_connections! ⇒ Object
- #exchanges ⇒ Object
-
#initialize ⇒ Publisher
constructor
Instance Methods ###.
- #publish_event(event) ⇒ Object
- #register_exchange(exchange_name) ⇒ Object
- #serialize_event(event) ⇒ Object
Constructor Details
#initialize ⇒ Publisher
Instance Methods ###
32 33 34 |
# File 'lib/active_pubsub/publisher.rb', line 32 def initialize connection end |
Class Attribute Details
.publishable_model_count ⇒ Object
Returns the value of attribute publishable_model_count.
11 12 13 |
# File 'lib/active_pubsub/publisher.rb', line 11 def publishable_model_count @publishable_model_count end |
.started ⇒ Object
Returns the value of attribute started.
10 11 12 |
# File 'lib/active_pubsub/publisher.rb', line 10 def started @started end |
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
5 6 7 |
# File 'lib/active_pubsub/publisher.rb', line 5 def connection @connection end |
Class Method Details
.increment_publishable_model_count! ⇒ Object
17 18 19 |
# File 'lib/active_pubsub/publisher.rb', line 17 def self.increment_publishable_model_count! self.publishable_model_count += 1 end |
.start ⇒ Object
21 22 23 24 25 |
# File 'lib/active_pubsub/publisher.rb', line 21 def self.start supervise_as :rabbit_publisher self.started = true end |
.started? ⇒ Boolean
27 28 29 |
# File 'lib/active_pubsub/publisher.rb', line 27 def self.started? self.started end |
Instance Method Details
#channel ⇒ Object
45 46 47 |
# File 'lib/active_pubsub/publisher.rb', line 45 def channel connection.channel end |
#clear_connections! ⇒ Object
40 41 42 43 |
# File 'lib/active_pubsub/publisher.rb', line 40 def clear_connections! channel.close connection.close end |
#exchanges ⇒ Object
49 50 51 |
# File 'lib/active_pubsub/publisher.rb', line 49 def exchanges @exchanges ||= {} end |
#publish_event(event) ⇒ Object
53 54 55 56 57 |
# File 'lib/active_pubsub/publisher.rb', line 53 def publish_event(event) ::ActiveRecord::Base.connection_pool.with_connection do exchanges[event.exchange].publish(serialize_event(event), :routing_key => event.routing_key) end end |
#register_exchange(exchange_name) ⇒ Object
63 64 65 |
# File 'lib/active_pubsub/publisher.rb', line 63 def register_exchange(exchange_name) exchanges[exchange_name] ||= channel.topic(exchange_name, :auto_delete => true) end |
#serialize_event(event) ⇒ Object
59 60 61 |
# File 'lib/active_pubsub/publisher.rb', line 59 def serialize_event(event) ::Marshal.dump(event) end |