Class: Messaging::Adapters::Postgres::Consumer

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Routing
Defined in:
lib/messaging/adapters/postgres/consumer.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Routing

#clear_routes!, #handle, included, #on

Class Method Details

.latest_known_transaction_idObject



9
10
11
# File 'lib/messaging/adapters/postgres/consumer.rb', line 9

def self.latest_known_transaction_id
  connection.select_value('select pg_snapshot_xmin(pg_current_snapshot())')
end

Instance Method Details

#shutdownObject



30
31
32
33
# File 'lib/messaging/adapters/postgres/consumer.rb', line 30

def shutdown
  Messaging.logger.info "[#{name}] Consumer stopped"
  release_lock
end

#startObject



13
14
15
16
17
18
19
20
21
22
# File 'lib/messaging/adapters/postgres/consumer.rb', line 13

def start
  obtain_lock
  refresh_latest_processed_transaction_id

  Messaging.logger.info "[#{name}] Consumer started"
  @running = true
  process_messages
ensure
  shutdown
end

#stopObject



24
25
26
27
28
# File 'lib/messaging/adapters/postgres/consumer.rb', line 24

def stop
  @running = false
  save
  Messaging.logger.info "[#{name}] Consumer stopping"
end