Class: Franz::Output::HTTP
- Inherits:
-
Object
- Object
- Franz::Output::HTTP
- Defined in:
- lib/franz/output/http.rb
Overview
HTTP output for Franz.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ HTTP
constructor
Start a new output in the background.
-
#join ⇒ Object
Join the Output thread.
-
#stop ⇒ Object
Stop the Output thread.
Constructor Details
#initialize(opts = {}) ⇒ HTTP
Start a new output in the background. We’ll consume from the input queue and ship events via HTTP.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/franz/output/http.rb', line 20 def initialize opts={} opts = { logger: Logger.new(STDOUT), tags: [], input: [], output: { server: 'http://localhost:3000', flush_size: 500, flush_interval: 10 } }.deep_merge!(opts) @statz = opts[:statz] || Franz::Stats.new @statz.create :num_output, 0 @logger = opts[:logger] @stop = false @foreground = opts[:foreground] server = opts[:output].delete :server @uri = URI(server) open_uri @flush_size = opts[:output][:flush_size] @flush_interval = opts[:output][:flush_interval] @lock = Mutex.new @messages = [] Thread.new do until @stop @lock.synchronize do true end sleep @flush_interval end end @thread = Thread.new do until @stop event = JSON::generate(opts[:input].shift) @lock.synchronize do enqueue event end log.trace \ event: 'publish', raw: event end end log.info event: 'output started' @thread.join if @foreground end |
Instance Method Details
#join ⇒ Object
Join the Output thread. Effectively only once.
78 79 80 81 82 |
# File 'lib/franz/output/http.rb', line 78 def join return if @foreground @foreground = true @thread.join end |
#stop ⇒ Object
Stop the Output thread. Effectively only once.
86 87 88 89 90 91 |
# File 'lib/franz/output/http.rb', line 86 def stop return if @foreground @foreground = true @thread.kill log.info event: 'output stopped' end |