fluent-plugin-in-websocket 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e0b75655a588094e89cdabd7789663717c9e8c1c
4
- data.tar.gz: f9ad787cafb8f147e1632dbdd57bf5c56d05db4c
3
+ metadata.gz: dd6d8ba597e13256344d8b2d85bdd883ec1269d6
4
+ data.tar.gz: 319a3cf40c5239e9e6bd35539dc7007e25bb228a
5
5
  SHA512:
6
- metadata.gz: c70fdc5d03dc99726f179a3b19d624dcb1e1a8f77c25b972ef41ec993a9c2f83380498876717beef20c80358d5458a3bccc6ea85226aa27e9809ac4e357810cb
7
- data.tar.gz: efaab6b0371fed610ae5eec4ceb5e7758d3e7ff3d21578b494350c91e9cbd9ba311e6fd0f815fc55c894837ec66a3b9d13e0e3e6010b95e371130a5147c8bf18
6
+ metadata.gz: 1694545912a88ce6555c7c03cc03a96eb76028b522beb0caa5bc4f425029811983cfc1b3d43d06c1d1047a401015bc7140f69e61f74e1ff1358d2c117dba8a21
7
+ data.tar.gz: 184d36d9f254a7b8392c815c4b513f2b00d45a3e9baf4c12c1d70bd856f0e21ab86db3589d8b18b5afa8556ebb30f7c1b38eff34c50bd9c6cb67afc576df1f15
@@ -4,12 +4,12 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "fluent-plugin-in-websocket"
7
- spec.version = "0.1.1"
7
+ spec.version = "0.1.2"
8
8
  spec.authors = ["Sebastian Szewczyk"]
9
9
  spec.email = ["sebryu@gmail.com"]
10
10
 
11
11
  spec.summary = "Fluent plugin for websocket input"
12
- spec.description = "Fluent plugin that uses em-websocket as input, not tested yet"
12
+ spec.description = "Fluent plugin that uses em-websocket as input. Don't have tests yet, but it works for me. For more info visit homepage https://github.com/sebryu/fluent_plugin_in_websocket."
13
13
  spec.homepage = "https://github.com/sebryu/fluent_plugin_in_websocket"
14
14
  spec.license = "MIT"
15
15
 
@@ -9,47 +9,52 @@ module Fluent
9
9
 
10
10
  # config_param defines a parameter. You can refer a parameter via @port instance variable
11
11
  # :default means this parameter is optional
12
- config_param :port, :integer, default: '8080'
13
- config_param :host, :integer, default: '127.0.0.1'
12
+ config_param :port, :integer, default: 8080
13
+ config_param :host, :string, default: '127.0.0.1'
14
14
 
15
15
  # This method is called before starting.
16
16
  # 'conf' is a Hash that includes configuration parameters.
17
17
  # If the configuration is invalid, raise Fluent::ConfigError.
18
18
  def configure(conf)
19
19
  super
20
-
21
- # You can also refer to raw parameter via conf[name].
22
- @port = conf['port']
23
- @host = conf['host']
24
20
  end
25
21
 
26
22
  # This method is called when starting.
27
23
  # Open sockets or files and create a thread here.
28
24
  def start
29
25
  super
30
- Thread.new(&method(:run))
26
+ @thread = Thread.new do
27
+ run
28
+ end
29
+ end
30
+
31
+ def log_message text
32
+ $log.info text
31
33
  end
32
34
 
33
35
  def run
34
36
  EM.run {
37
+ log_message "EM will be runned on #{@host}:#{@port}"
35
38
  EM::WebSocket.run(host: @host, port: @port) do |ws|
36
39
  ws.onopen { |handshake|
37
- puts "WebSocket connection open"
38
-
39
- # Access properties on the EM::WebSocket::Handshake object, e.g.
40
- # path, query_string, origin, headers
41
-
42
- # Publish message to the client
40
+ log_message "WebSocket connection open"
43
41
  ws.send "Hello Client, you connected to #{handshake.path}"
44
42
  }
45
43
 
46
- ws.onclose { puts "Connection closed" }
44
+ ws.onerror { |e|
45
+ log_message "error occured"
46
+ log_message "error: #{e}"
47
+ }
48
+
49
+ ws.onclose { |e|
50
+ log_message "Connection closed"
51
+ log_message "reason: #{e}"
52
+ }
47
53
 
48
54
  ws.onmessage { |msg|
49
- puts "Recieved message: #{msg}"
55
+ log_message "Recieved message: #{msg}"
50
56
  data = JSON.parse(msg)
51
- router.emit(data.label, Engine.now, data.record)
52
-
57
+ router.emit(data['label'], Engine.now, data['record'])
53
58
  ws.send "Pong: #{msg}"
54
59
  }
55
60
  end
@@ -59,7 +64,10 @@ module Fluent
59
64
  # This method is called when shutting down.
60
65
  # Shutdown the thread and close sockets or files here.
61
66
  def shutdown
62
- puts 'SHOULD CLOSE DOWN CONNECTION'
67
+ super
68
+ EM.stop
69
+ Thread::kill(@thread)
70
+ log_message 'closed EM and thread'
63
71
  end
64
72
  end
65
73
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-in-websocket
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastian Szewczyk
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-06-03 00:00:00.000000000 Z
11
+ date: 2016-06-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -72,7 +72,8 @@ dependencies:
72
72
  - - "~>"
73
73
  - !ruby/object:Gem::Version
74
74
  version: 0.5.1
75
- description: Fluent plugin that uses em-websocket as input, not tested yet
75
+ description: Fluent plugin that uses em-websocket as input. Don't have tests yet,
76
+ but it works for me. For more info visit homepage https://github.com/sebryu/fluent_plugin_in_websocket.
76
77
  email:
77
78
  - sebryu@gmail.com
78
79
  executables: []