Class: Zebra::Queue

Inherits:
Object
  • Object
show all
Defined in:
lib/zebra/queue.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Queue

Returns a new instance of Queue.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/zebra/queue.rb', line 6

def initialize(config)
  @log = config[:logger] || Logger.new(STDERR)
  @frontend_uri = config[:frontend_uri] || 'tcp://*:5559'
  @backend_uri = config[:backend_uri] || 'tcp://*:5560'
  @context = ZMQ::Context.new

  # Socket facing clients
  @frontend = context.socket(ZMQ::ROUTER)

  # Socket facing services
  @backend = context.socket(ZMQ::DEALER)
  trap("INT") do
    @log.info "Shutting down."
    @frontend.close unless @frontend.nil?
    @backend.close unless @backend.nil?
    @context.terminate unless @context.nil?
    exit
  end
end

Instance Attribute Details

#backendObject

Returns the value of attribute backend.



5
6
7
# File 'lib/zebra/queue.rb', line 5

def backend
  @backend
end

#backend_uriObject

Returns the value of attribute backend_uri.



5
6
7
# File 'lib/zebra/queue.rb', line 5

def backend_uri
  @backend_uri
end

#contextObject

Returns the value of attribute context.



5
6
7
# File 'lib/zebra/queue.rb', line 5

def context
  @context
end

#frontendObject

Returns the value of attribute frontend.



5
6
7
# File 'lib/zebra/queue.rb', line 5

def frontend
  @frontend
end

#frontend_uriObject

Returns the value of attribute frontend_uri.



5
6
7
# File 'lib/zebra/queue.rb', line 5

def frontend_uri
  @frontend_uri
end

#logObject

Returns the value of attribute log.



5
6
7
# File 'lib/zebra/queue.rb', line 5

def log
  @log
end

#pollerObject

Returns the value of attribute poller.



5
6
7
# File 'lib/zebra/queue.rb', line 5

def poller
  @poller
end

Instance Method Details

#dispatchObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/zebra/queue.rb', line 26

def dispatch
  @frontend.bind(@frontend_uri)
  @backend.bind(@backend_uri)
  begin
    # Start built-in device
    @poller = ZMQ::Device.new(ZMQ::QUEUE,frontend,backend)
  rescue Interrupt => e
    @log.info("Caught interrupt signal...")
  end

  @frontend.close
  @backend.close
  @context.terminate
end