Class: ActivePubsub::Publisher

Inherits:
Object
  • Object
show all
Includes:
Celluloid
Defined in:
lib/active_pubsub/publisher.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePublisher

Instance Methods ###



32
33
34
# File 'lib/active_pubsub/publisher.rb', line 32

def initialize
  connection
end

Class Attribute Details

.publishable_model_countObject

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

.startedObject

Returns the value of attribute started.



10
11
12
# File 'lib/active_pubsub/publisher.rb', line 10

def started
  @started
end

Instance Attribute Details

#connectionObject

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

.startObject



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

Returns:

  • (Boolean)


27
28
29
# File 'lib/active_pubsub/publisher.rb', line 27

def self.started?
  self.started
end

Instance Method Details

#channelObject



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

#exchangesObject



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