class Fluent::WebsocketInput
Public Instance Methods
configure(conf)
click to toggle source
This method is called before starting. ‘conf’ is a Hash that includes configuration parameters. If the configuration is invalid, raise Fluent::ConfigError.
Calls superclass method
# File lib/fluent/plugin/in_websocket.rb, line 18 def configure(conf) super end
log_message(text)
click to toggle source
# File lib/fluent/plugin/in_websocket.rb, line 31 def log_message text $log.info text end
run()
click to toggle source
# File lib/fluent/plugin/in_websocket.rb, line 35 def run EM.run { log_message "EM will be runned on #{@host}:#{@port}" EM::WebSocket.run(host: @host, port: @port) do |ws| ws.onopen { |handshake| log_message "WebSocket connection open" ws.send "Hello Client, you connected to #{handshake.path}" } ws.onerror { |e| log_message "error occured" log_message "error: #{e}" } ws.onclose { |e| log_message "Connection closed" log_message "reason: #{e}" } ws.onmessage { |msg| log_message "Recieved message: #{msg}" data = JSON.parse(msg) router.emit(data['label'], Engine.now, data['record']) ws.send "Pong: #{msg}" } end } end
shutdown()
click to toggle source
This method is called when shutting down. Shutdown the thread and close sockets or files here.
Calls superclass method
# File lib/fluent/plugin/in_websocket.rb, line 66 def shutdown super EM.stop Thread::kill(@thread) log_message 'closed EM and thread' end
start()
click to toggle source
This method is called when starting. Open sockets or files and create a thread here.
Calls superclass method
# File lib/fluent/plugin/in_websocket.rb, line 24 def start super @thread = Thread.new do run end end