Sha256: 123ca5381bcfc6d2610083a16ade546f4cfed505ceca9144b4d8114e991d6afa

Contents?: true

Size: 720 Bytes

Versions: 2

Compression:

Stored size: 720 Bytes

Contents

require 'rbczmq'

module Zlogger
  class Reader
    attr :options

    def initialize(options={})
      @options = options
    end

    def sub_socket
      @sub_socket ||=
          begin
            socket = context.socket :SUB
            socket.subscribe ""
            socket.connect("tcp://#{address}:#{port}")
            socket
          end
    end

    def context
      @context ||= (ZMQ.context || ZMQ::Context.new)
    end

    def port
      options[:port] ||= DEFAULT_PORT + 1
    end

    def address
      options[:address] ||= "0.0.0.0"
    end

    def run
      begin
        loop do
          puts sub_socket.recv
        end
      rescue Interrupt
        # exit nicely
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
zlogger-0.1.0 lib/zlogger/reader.rb
zlogger-0.0.2 lib/zlogger/reader.rb