fluent-plugin-nng 0.1.1 → 1.0.0

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
  SHA256:
3
- metadata.gz: 3a73a8128392a18a1caaaf83a3bc60bccd185837527916048752652c658622c5
4
- data.tar.gz: 02f86cc9c3c5cd7477f8b8e028c457d0cef6c7f1164c1748c45e5476b645a8af
3
+ metadata.gz: f0bf929dc703bbcecd109a42516ab9cccf40bd056a9e9fd21645884c0dd1a123
4
+ data.tar.gz: d3be3ba9da322adfd364165efa83b55659983ff31ba06f3be6f437e6f026e8a1
5
5
  SHA512:
6
- metadata.gz: 66a0400c41fc3bbf9b496da77d196a6a22c60be8d5cddd8df8a5a6d5e8d83080740ef8b8164fa9d819e4180aeac2a4302791b3f5cab4b612455c464444cde506
7
- data.tar.gz: 2522e1e55c623a2ad12cf95ba1511e2502f89e7cbbe702012f6463b8e0c95e6978aeabc26f6ebc97b35e082e0b01a4a490671e5d07846bf2e489b9642da2146d
6
+ metadata.gz: cabfb3cf6166341d617d60df6ffe4828fad9188b9407734dfcf77e0282679a76ecb5445c9de2eaead1c8024a06193b595ca05f44cb41c8f8f5d3e0fc7149d022
7
+ data.tar.gz: ee9e6fc8de98325509a7544c8996091ac0eb08e15ae8661f1903be3f8473ff0562027f352c119f8e2f7e6460be20c3f76fcbd452d820f45303800ea4e9986e0b
data/-la ADDED
@@ -0,0 +1,231 @@
1
+
2
+ Δ README.md
3
+ ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
4
+
5
+ ───────────────────────────────────────────────────────────────────────────────────────┐
6
+ • 19: parses the data using the fluentd-plugin [fluent-plugin-parser-protobuf](https:/ │
7
+ ───────────────────────────────────────────────────────────────────────────────────────┘
8
+
9
+ ```
10
+ <source>
11
+  @type nng
12
+  @type nng_in
13
+  @id input_nng
14
+  <parse>
15
+  @type protobuf
16
+
17
+ ───────────────────────────────────────────────────────────────────────────────────────┐
18
+ • 28: parses the data using the fluentd-plugin [fluent-plugin-parser-protobuf](https:/ │
19
+ ───────────────────────────────────────────────────────────────────────────────────────┘
20
+  protobuf_version protobuf3
21
+  </parse>
22
+  uri tcp://127.0.0.1:5557
23
+  tag nng.*
24
+ </source>
25
+
26
+ <match nng.**>
27
+
28
+ ───────────────────────────────────────────────────────────────────────────────────────┐
29
+ • 55: using the detectmate `LogSchema` using [fluent-plugin-detectmate](https://github │
30
+ ───────────────────────────────────────────────────────────────────────────────────────┘
31
+ </source>
32
+
33
+ <match nng.**>
34
+  @type nng
35
+  @type nng_out
36
+  uri tcp://127.0.0.1:5557
37
+  <inject>
38
+  hostname_key hostname
39
+
40
+ Δ fluent-plugin-nng.gemspec
41
+ ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
42
+
43
+ ─────────────────────────────────────────────────────────────┐
44
+ • 3: $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) │
45
+ ─────────────────────────────────────────────────────────────┘
46
+
47
+ Gem::Specification.new do |spec|
48
+  spec.name = "fluent-plugin-nng"
49
+  spec.version = "0.1.1"
50
+  spec.version = "1.0.0"
51
+  spec.authors = ["whotwagner"]
52
+  spec.email = ["code@feedyourhead.at"]
53
+
54
+
55
+ ───────────────────────────────────────┐
56
+ • 21: Gem::Specification.new do |spec| │
57
+ ───────────────────────────────────────┘
58
+  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
59
+  spec.require_paths = ["lib"]
60
+
61
+  spec.add_development_dependency "bundler", "~> 2.6.9"
62
+  spec.add_development_dependency "rake", "~> 13.3.1"
63
+  spec.add_development_dependency "test-unit", "~> 3.6.7"
64
+  spec.add_runtime_dependency "nng-ruby", "~> 1.0.1"
65
+  spec.add_development_dependency 'bundler', '~> 2.6.9'
66
+  spec.add_development_dependency 'rake', '~> 13.3.1'
67
+  spec.add_development_dependency 'test-unit', '~> 3.6.7'
68
+  spec.add_runtime_dependency 'nng', '~> 1.0.1'
69
+  spec.add_runtime_dependency "fluentd", [">= 0.14.10", "< 2"]
70
+ end
71
+
72
+ Δ lib/fluent/plugin/in_nng.rb
73
+ ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
74
+
75
+ ──────┐
76
+ • 15: │
77
+ ──────┘
78
+
79
+ require 'fluent/plugin/input'
80
+ require 'nng'
81
+ require 'uri'
82
+
83
+ module Fluent
84
+  module Plugin
85
+  class NngInput < Fluent::Plugin::Input
86
+  Fluent::Plugin.register_input('nng', self)
87
+  Fluent::Plugin.register_input('nng_in', self)
88
+
89
+  helpers :parser, :compat_parameters
90
+  helpers :parser, :compat_parameters, :thread
91
+
92
+  config_param :uri, :string, default: 'tcp://127.0.0.1:5555'
93
+  config_param :recv_timeout, :float, default: 1.0
94
+  config_param :tag, :string, default: 'nng.input'
95
+
96
+  def configure(conf)
97
+  if @uri !~ /\A#{URI::RFC2396_PARSER.make_regexp(['tcp', 'ipc', 'inproc', 'ws', 'tls+tcp'])}\z/
98
+
99
+ ────────────────────┐
100
+ • 55: module Fluent │
101
+ ────────────────────┘
102
+  if uri.scheme == 'ipc'
103
+  File.exist?(uri.path) && File.delete(uri.path)
104
+  end
105
+  @socket = NNG::Socket.new(:pair0)
106
+  @socket = NNG::Socket::Pair0.new
107
+  @socket.listen(@uri)
108
+  @socket.recv_timeout = 5000
109
+  @socket.recv_timeout = @recv_timeout
110
+  end
111
+
112
+  def start
113
+  super
114
+  listen
115
+  run
116
+  thread_create(:nng_input_run, &method(:run))
117
+  end
118
+
119
+  def run
120
+  log.info "start looping.."
121
+  loop do
122
+  begin
123
+   msg = nil
124
+   until msg
125
+   if @stop
126
+   return
127
+  end
128
+  begin
129
+  msg = @socket.recv
130
+  rescue NNG::Error
131
+  next
132
+  end
133
+  msg = nil
134
+  until msg
135
+  if @stop
136
+  return
137
+  end
138
+  tag = "nng.input"
139
+  @parser.parse(msg) do |time, record|
140
+  router.emit(tag, time, record)
141
+  begin
142
+  msg = @socket.receive
143
+  rescue Timeout::Error
144
+  sleep 0.01
145
+  next
146
+  end
147
+  rescue NNG::Error => e
148
+  log.warn "Error in processing message.", :error_class => e.class, :error => e
149
+  end
150
+  @parser.parse(msg) do |time, record|
151
+  router.emit(@tag, time || Fluent::Engine.now, record)
152
+  end
153
+  end
154
+
155
+
156
+ Δ lib/fluent/plugin/out_nng.rb
157
+ ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
158
+
159
+ ───────────────────┐
160
+ • 4: require 'nng' │
161
+ ───────────────────┘
162
+
163
+ module Fluent::Plugin
164
+  class NngOutput < Fluent::Plugin::Output
165
+  Fluent::Plugin.register_output('nng', self)
166
+  Fluent::Plugin.register_output('nng_out', self)
167
+
168
+  helpers :formatter, :inject, :compat_parameters
169
+
170
+  config_param :uri, :string, default: 'tcp://127.0.0.1:5559'
171
+  config_param :max_retry, :integer, default: 1000
172
+  config_param :max_retry, :integer, default: 100
173
+  config_param :retry_time, :integer, default: 5
174
+
175
+  config_section :format do
176
+  config_set_default :@type, 'json'
177
+
178
+ ────────────────────────────┐
179
+ • 19: module Fluent::Plugin │
180
+ ────────────────────────────┘
181
+  def initialize
182
+  super
183
+  @formatter = nil
184
+  log.info 'Initializing'
185
+  end
186
+
187
+  def configure(conf)
188
+  log.info "configuring.."
189
+  compat_parameters_convert(conf, :formatter, :inject)
190
+  if @uri !~ /\A#{URI::RFC2396_PARSER.make_regexp(['tcp', 'ipc', 'inproc', 'ws', 'tls+tcp'])}\z/
191
+  raise Fluent::ConfigError, 'uri must be one of: tcp:// ipc:// inproc:// ws:// or tls+tcp://'
192
+  end
193
+
194
+  super
195
+  log.info "Creating formatter"
196
+  @formatter = formatter_create
197
+  log.info "Formatter loaded"
198
+  end
199
+
200
+  def start
201
+  super
202
+  log.info "Starting listener at: #{@uri}"
203
+  log.info "Initiating connection to: #{@uri}"
204
+  connect
205
+  end
206
+
207
+
208
+ ────────────────────────────┐
209
+ • 46: module Fluent::Plugin │
210
+ ────────────────────────────┘
211
+  end
212
+
213
+  def connect
214
+  @socket = NNG::Socket.new(:pair0)
215
+  @socket = NNG::Socket::Pair0.new
216
+  try = 0
217
+
218
+  begin
219
+  @socket.dial(@uri)
220
+  rescue NNG::Error => e
221
+  rescue => e
222
+  log.error(e)
223
+  log.info("Retry in 5sec")
224
+  sleep(5)
225
+  sleep(@retry_time)
226
+  try += 1
227
+  if try >= @max_retry
228
+  if @max_retry > 0 && try >= @max_retry
229
+  raise Fluent::UnrecoverableError, e.message
230
+  end
231
+  retry
data/README.md CHANGED
@@ -19,7 +19,7 @@ parses the data using the fluentd-plugin [fluent-plugin-parser-protobuf](https:/
19
19
 
20
20
  ```
21
21
  <source>
22
- @type nng
22
+ @type nng_in
23
23
  @id input_nng
24
24
  <parse>
25
25
  @type protobuf
@@ -28,7 +28,6 @@ parses the data using the fluentd-plugin [fluent-plugin-parser-protobuf](https:/
28
28
  protobuf_version protobuf3
29
29
  </parse>
30
30
  uri tcp://127.0.0.1:5557
31
- tag nng.*
32
31
  </source>
33
32
 
34
33
  <match nng.**>
@@ -56,7 +55,7 @@ using the detectmate `LogSchema` using [fluent-plugin-detectmate](https://github
56
55
  </source>
57
56
 
58
57
  <match nng.**>
59
- @type nng
58
+ @type nng_out
60
59
  uri tcp://127.0.0.1:5557
61
60
  <inject>
62
61
  hostname_key hostname
@@ -2,10 +2,10 @@ lib = File.expand_path("../lib", __FILE__)
2
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  Gem::Specification.new do |spec|
5
- spec.name = "fluent-plugin-nng"
6
- spec.version = "0.1.1"
7
- spec.authors = ["whotwagner"]
8
- spec.email = ["code@feedyourhead.at"]
5
+ spec.name = 'fluent-plugin-nng'
6
+ spec.version = '1.0.0'
7
+ spec.authors = ['whotwagner']
8
+ spec.email = ['code@feedyourhead.at']
9
9
 
10
10
  spec.summary = %q{Fluentd input-/output plugin for nanomsg-ng.}
11
11
  spec.description = %q{Fluentd input-/output plugin for nanomsg-ng.}
@@ -21,9 +21,9 @@ Gem::Specification.new do |spec|
21
21
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
22
22
  spec.require_paths = ["lib"]
23
23
 
24
- spec.add_development_dependency "bundler", "~> 2.6.9"
25
- spec.add_development_dependency "rake", "~> 13.3.1"
26
- spec.add_development_dependency "test-unit", "~> 3.6.7"
27
- spec.add_runtime_dependency "nng-ruby", "~> 1.0.1"
24
+ spec.add_development_dependency 'bundler', '~> 2.6.9'
25
+ spec.add_development_dependency 'rake', '~> 13.3.1'
26
+ spec.add_development_dependency 'test-unit', '~> 3.6.7'
27
+ spec.add_runtime_dependency 'nng', '~> 1.0.1'
28
28
  spec.add_runtime_dependency "fluentd", [">= 0.14.10", "< 2"]
29
29
  end
@@ -15,15 +15,18 @@
15
15
 
16
16
  require 'fluent/plugin/input'
17
17
  require 'nng'
18
+ require 'uri'
18
19
 
19
20
  module Fluent
20
21
  module Plugin
21
22
  class NngInput < Fluent::Plugin::Input
22
- Fluent::Plugin.register_input('nng', self)
23
+ Fluent::Plugin.register_input('nng_in', self)
23
24
 
24
- helpers :parser, :compat_parameters
25
+ helpers :parser, :compat_parameters, :thread
25
26
 
26
27
  config_param :uri, :string, default: 'tcp://127.0.0.1:5555'
28
+ config_param :recv_timeout, :float, default: 1.0
29
+ config_param :tag, :string, default: 'nng.input'
27
30
 
28
31
  def configure(conf)
29
32
  if @uri !~ /\A#{URI::RFC2396_PARSER.make_regexp(['tcp', 'ipc', 'inproc', 'ws', 'tls+tcp'])}\z/
@@ -52,38 +55,34 @@ module Fluent
52
55
  if uri.scheme == 'ipc'
53
56
  File.exist?(uri.path) && File.delete(uri.path)
54
57
  end
55
- @socket = NNG::Socket.new(:pair0)
58
+ @socket = NNG::Socket::Pair0.new
56
59
  @socket.listen(@uri)
57
- @socket.recv_timeout = 5000
60
+ @socket.recv_timeout = @recv_timeout
58
61
  end
59
62
 
60
63
  def start
61
64
  super
62
65
  listen
63
- run
66
+ thread_create(:nng_input_run, &method(:run))
64
67
  end
65
68
 
66
69
  def run
67
70
  log.info "start looping.."
68
71
  loop do
69
- begin
70
- msg = nil
71
- until msg
72
- if @stop
73
- return
74
- end
75
- begin
76
- msg = @socket.recv
77
- rescue NNG::Error
78
- next
79
- end
72
+ msg = nil
73
+ until msg
74
+ if @stop
75
+ return
80
76
  end
81
- tag = "nng.input"
82
- @parser.parse(msg) do |time, record|
83
- router.emit(tag, time, record)
77
+ begin
78
+ msg = @socket.receive
79
+ rescue Timeout::Error
80
+ sleep 0.01
81
+ next
84
82
  end
85
- rescue NNG::Error => e
86
- log.warn "Error in processing message.", :error_class => e.class, :error => e
83
+ end
84
+ @parser.parse(msg) do |time, record|
85
+ router.emit(@tag, time || Fluent::Engine.now, record)
87
86
  end
88
87
  end
89
88
 
@@ -4,12 +4,13 @@ require 'nng'
4
4
 
5
5
  module Fluent::Plugin
6
6
  class NngOutput < Fluent::Plugin::Output
7
- Fluent::Plugin.register_output('nng', self)
7
+ Fluent::Plugin.register_output('nng_out', self)
8
8
 
9
9
  helpers :formatter, :inject, :compat_parameters
10
10
 
11
11
  config_param :uri, :string, default: 'tcp://127.0.0.1:5559'
12
- config_param :max_retry, :integer, default: 1000
12
+ config_param :max_retry, :integer, default: 100
13
+ config_param :retry_time, :integer, default: 5
13
14
 
14
15
  config_section :format do
15
16
  config_set_default :@type, 'json'
@@ -18,21 +19,25 @@ module Fluent::Plugin
18
19
  def initialize
19
20
  super
20
21
  @formatter = nil
22
+ log.info 'Initializing'
21
23
  end
22
24
 
23
25
  def configure(conf)
26
+ log.info "configuring.."
24
27
  compat_parameters_convert(conf, :formatter, :inject)
25
28
  if @uri !~ /\A#{URI::RFC2396_PARSER.make_regexp(['tcp', 'ipc', 'inproc', 'ws', 'tls+tcp'])}\z/
26
29
  raise Fluent::ConfigError, 'uri must be one of: tcp:// ipc:// inproc:// ws:// or tls+tcp://'
27
30
  end
28
31
 
29
32
  super
33
+ log.info "Creating formatter"
30
34
  @formatter = formatter_create
35
+ log.info "Formatter loaded"
31
36
  end
32
37
 
33
38
  def start
34
39
  super
35
- log.info "Starting listener at: #{@uri}"
40
+ log.info "Initiating connection to: #{@uri}"
36
41
  connect
37
42
  end
38
43
 
@@ -41,17 +46,17 @@ module Fluent::Plugin
41
46
  end
42
47
 
43
48
  def connect
44
- @socket = NNG::Socket.new(:pair0)
49
+ @socket = NNG::Socket::Pair0.new
45
50
  try = 0
46
51
 
47
52
  begin
48
53
  @socket.dial(@uri)
49
- rescue NNG::Error => e
54
+ rescue => e
50
55
  log.error(e)
51
56
  log.info("Retry in 5sec")
52
- sleep(5)
57
+ sleep(@retry_time)
53
58
  try += 1
54
- if try >= @max_retry
59
+ if @max_retry > 0 && try >= @max_retry
55
60
  raise Fluent::UnrecoverableError, e.message
56
61
  end
57
62
  retry
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-nng
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - whotwagner
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2026-04-02 00:00:00.000000000 Z
10
+ date: 2026-04-27 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: bundler
@@ -53,7 +52,7 @@ dependencies:
53
52
  - !ruby/object:Gem::Version
54
53
  version: 3.6.7
55
54
  - !ruby/object:Gem::Dependency
56
- name: nng-ruby
55
+ name: nng
57
56
  requirement: !ruby/object:Gem::Requirement
58
57
  requirements:
59
58
  - - "~>"
@@ -93,6 +92,7 @@ executables: []
93
92
  extensions: []
94
93
  extra_rdoc_files: []
95
94
  files:
95
+ - "-la"
96
96
  - LICENSE
97
97
  - README.md
98
98
  - Rakefile
@@ -103,7 +103,6 @@ homepage: https://github.com/ait-detectmate/fluent-plugin-nng
103
103
  licenses:
104
104
  - EUPL-1.2
105
105
  metadata: {}
106
- post_install_message:
107
106
  rdoc_options: []
108
107
  require_paths:
109
108
  - lib
@@ -118,8 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
117
  - !ruby/object:Gem::Version
119
118
  version: '0'
120
119
  requirements: []
121
- rubygems_version: 3.4.10
122
- signing_key:
120
+ rubygems_version: 3.6.2
123
121
  specification_version: 4
124
122
  summary: Fluentd input-/output plugin for nanomsg-ng.
125
123
  test_files: []