class LogStash::Outputs::WebSocket
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.
Public Instance Methods
receive(event)
click to toggle source
# File lib/logstash/outputs/websocket_topics.rb, line 39 def receive(event) topic = event['topic'] json = JSON.generate(event) if @channels.has_key?(topic) @channels[topic].publish(json) else require "logstash/outputs/websocket_topics/pubsub" pubsub = LogStash::Outputs::WebSocket::Pubsub.new pubsub.logger = @logger @channels[topic] = pubsub pubsub.publish(json) end # if end
register()
click to toggle source
# File lib/logstash/outputs/websocket_topics.rb, line 22 def register require "ftw" require "logstash/outputs/websocket_topics/app" @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