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 ###
34 35 36 |
# File 'lib/active_pubsub/publisher.rb', line 34 def initialize connection end |
Class Attribute Details
.publishable_model_count ⇒ Object
Returns the value of attribute publishable_model_count.
13 14 15 |
# File 'lib/active_pubsub/publisher.rb', line 13 def publishable_model_count @publishable_model_count end |
.started ⇒ Object
Returns the value of attribute started.
12 13 14 |
# File 'lib/active_pubsub/publisher.rb', line 12 def started @started end |
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
7 8 9 |
# File 'lib/active_pubsub/publisher.rb', line 7 def connection @connection end |
Class Method Details
.increment_publishable_model_count! ⇒ Object
19 20 21 |
# File 'lib/active_pubsub/publisher.rb', line 19 def self.increment_publishable_model_count! self.publishable_model_count += 1 end |
.start ⇒ Object
23 24 25 26 27 |
# File 'lib/active_pubsub/publisher.rb', line 23 def self.start supervise_as :rabbit_publisher self.started = true end |
.started? ⇒ Boolean
29 30 31 |
# File 'lib/active_pubsub/publisher.rb', line 29 def self.started? self.started end |
Instance Method Details
#channel ⇒ Object
47 48 49 |
# File 'lib/active_pubsub/publisher.rb', line 47 def channel connection.channel end |
#clear_connections! ⇒ Object
42 43 44 45 |
# File 'lib/active_pubsub/publisher.rb', line 42 def clear_connections! channel.close connection.close end |
#exchanges ⇒ Object
51 52 53 |
# File 'lib/active_pubsub/publisher.rb', line 51 def exchanges @exchanges ||= {} end |
#publish_event(event) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/active_pubsub/publisher.rb', line 55 def publish_event(event) ::ActiveRecord::Base.connection_pool.with_connection do puts event.inspect exchanges[event.exchange].publish(serialize_event(event), :routing_key => event.routing_key) end end |
#register_exchange(exchange_name) ⇒ Object
67 68 69 |
# File 'lib/active_pubsub/publisher.rb', line 67 def register_exchange(exchange_name) exchanges[exchange_name] ||= channel.topic(exchange_name, :auto_delete => true) end |
#serialize_event(event) ⇒ Object
63 64 65 |
# File 'lib/active_pubsub/publisher.rb', line 63 def serialize_event(event) ::Marshal.dump(event) end |