Class: Zebra::Queue
- Inherits:
-
Object
- Object
- Zebra::Queue
- Defined in:
- lib/zebra/queue.rb
Instance Attribute Summary collapse
-
#backend ⇒ Object
Returns the value of attribute backend.
-
#backend_uri ⇒ Object
Returns the value of attribute backend_uri.
-
#context ⇒ Object
Returns the value of attribute context.
-
#frontend ⇒ Object
Returns the value of attribute frontend.
-
#frontend_uri ⇒ Object
Returns the value of attribute frontend_uri.
-
#log ⇒ Object
Returns the value of attribute log.
-
#poller ⇒ Object
Returns the value of attribute poller.
Instance Method Summary collapse
- #dispatch ⇒ Object
-
#initialize(config) ⇒ Queue
constructor
A new instance of Queue.
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
#backend ⇒ Object
Returns the value of attribute backend.
5 6 7 |
# File 'lib/zebra/queue.rb', line 5 def backend @backend end |
#backend_uri ⇒ Object
Returns the value of attribute backend_uri.
5 6 7 |
# File 'lib/zebra/queue.rb', line 5 def backend_uri @backend_uri end |
#context ⇒ Object
Returns the value of attribute context.
5 6 7 |
# File 'lib/zebra/queue.rb', line 5 def context @context end |
#frontend ⇒ Object
Returns the value of attribute frontend.
5 6 7 |
# File 'lib/zebra/queue.rb', line 5 def frontend @frontend end |
#frontend_uri ⇒ Object
Returns the value of attribute frontend_uri.
5 6 7 |
# File 'lib/zebra/queue.rb', line 5 def frontend_uri @frontend_uri end |
#log ⇒ Object
Returns the value of attribute log.
5 6 7 |
# File 'lib/zebra/queue.rb', line 5 def log @log end |
#poller ⇒ Object
Returns the value of attribute poller.
5 6 7 |
# File 'lib/zebra/queue.rb', line 5 def poller @poller end |
Instance Method Details
#dispatch ⇒ Object
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 |