Class: Chasqui::Broker

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/chasqui/broker.rb

Direct Known Subclasses

MultiBroker

Constant Summary collapse

ShutdownSignals =
%w(INT QUIT ABRT TERM).freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBroker

Returns a new instance of Broker.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/chasqui/broker.rb', line 11

def initialize
  @shutdown_requested = nil
  @config = Chasqui.config.dup
  @redis_namespace = @config.redis.namespace

  # The broker uses it's own private redis connection for two reasons:
  # 1. subscribers may use a different (or no) redis namespace than chasqui
  # 2. sharing the connection with unsuspecting clients could result in
  #    the broker blocking forever
  @redis = Redis.new @config.redis.client.options
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



4
5
6
# File 'lib/chasqui/broker.rb', line 4

def config
  @config
end

#redisObject (readonly)

Returns the value of attribute redis.



4
5
6
# File 'lib/chasqui/broker.rb', line 4

def redis
  @redis
end

#redis_namespaceObject (readonly)

Returns the value of attribute redis_namespace.



4
5
6
# File 'lib/chasqui/broker.rb', line 4

def redis_namespace
  @redis_namespace
end

Class Method Details

.startObject



37
38
39
# File 'lib/chasqui/broker.rb', line 37

def start
  Chasqui::MultiBroker.new.start
end

Instance Method Details

#forward_eventObject



32
33
34
# File 'lib/chasqui/broker.rb', line 32

def forward_event
  raise NotImplementedError.new "please define #forward_event in a subclass of #{self.class.name}"
end

#startObject



23
24
25
26
27
28
29
30
# File 'lib/chasqui/broker.rb', line 23

def start
  install_signal_handlers

  logger.info "broker started with pid #{Process.pid}"
  logger.info "configured to fetch events from #{inbox} on #{redis.inspect}"

  until_shutdown_requested { forward_event }
end