Class: LogStash::Outputs::WebSocket
- Inherits:
-
Base
- Object
- Base
- LogStash::Outputs::WebSocket
- Defined in:
- lib/logstash/outputs/websocket.rb
Overview
This output runs a websocket server and publishes any messages to all connected websocket clients.
You can connect to it with ws://<host>:<port>/
If no clients are connected, any messages received are ignored.
Instance Method Summary collapse
Instance Method Details
#make_pubsub(topic) ⇒ Object
21 22 23 24 |
# File 'lib/logstash/outputs/websocket.rb', line 21 def make_pubsub(topic) pubsub = Logstash::Outputs::WebSocket::Pubsub.new pubsub.logger = @logger end |
#receive(event) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/logstash/outputs/websocket.rb', line 45 def receive(event) json = event.to_json topic = json.topic if @channels.has_key?(topic) @channels[topic].publish(json) else pubsub = make_pubsub(topic) @channels[topic] = pubsub pubsub.publish(json) end # if end |
#register ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/logstash/outputs/websocket.rb', line 27 def register require "ftw" require "logstash/outputs/websocket/app" require "logstash/outputs/websocket/pubsub" @channels = {} @server = Thread.new(@channels) do |channels| begin Rack::Handler::FTW.run(LogStash::Outputs::WebSocket::App.new(channels, @logger), :Host => @host, :Port => @port) rescue => e @logger.error("websocket server failed", :exception => e) sleep 1 retry end end end |