fluent-plugin-mqtt-io 0.3.1 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 97803d6c5941eb7ff068d9d8e7205c9a78cc629b
4
- data.tar.gz: 8f492394371c32718ad1f97181597efe2192bf08
3
+ metadata.gz: de59247eae560befc4d28b446d68e3e9ef650e90
4
+ data.tar.gz: 6e9eb9e006557bdad477407ec7d648bacf73d9ce
5
5
  SHA512:
6
- metadata.gz: a022d9dd82ed38ced4b9cfc89e7d01da5cca628dd6030bc36687df3594409dc25953a027ab9a5a2390f3aa7ef12081114b46c81311d8904a52e342f71f14cd3c
7
- data.tar.gz: 00e999e1448d738401eca559d54670c2dff6586f534342af9d09c9caf3f9f745b4bcbbc3704e55210b55485f7bf210e8cce54c21358ce96c00b8be3a0728802b
6
+ metadata.gz: f96037a4572be86d1acf889569d41f814dfc13270eda73dbb7b704c2de05e8ad83723c3648d90e1f530a443ea52bd189f88e861982ed376e67d320964fef5afd
7
+ data.tar.gz: 18a41fef17638a172e500df27aa51b45da20e3ef022823893f358d26ed581bdae5d86af4e1bb0568ffb2054da1fc108051123b93d4010b46980f31905ff552a3
data/README.md CHANGED
@@ -30,6 +30,8 @@ fluent-plugin-mqtt-io provides Input and Output Plugins for MQTT.
30
30
 
31
31
  Input Plugin can be used via source directive in the configuration.
32
32
 
33
+ For fluent-plugin-mqtt-io <= 0.2.3
34
+
33
35
  ```
34
36
 
35
37
  <source>
@@ -41,6 +43,20 @@ Input Plugin can be used via source directive in the configuration.
41
43
 
42
44
  ```
43
45
 
46
+ For fluent-plugin-mqtt-io ~> v0.3.0
47
+
48
+ ```
49
+
50
+ <source>
51
+ @type mqtt
52
+ host 127.0.0.1
53
+ port 1883
54
+ format json
55
+ </source>
56
+
57
+ ```
58
+
59
+
44
60
  The default MQTT topic is "#". Configurable options are the following:
45
61
 
46
62
  - **host**: IP address of MQTT broker
@@ -69,6 +85,8 @@ Input Plugin supports @label directive.
69
85
 
70
86
  Output Plugin can be used via match directive.
71
87
 
88
+ For fluent-plugin-mqtt-io <= 0.2.3
89
+
72
90
  ```
73
91
 
74
92
  <match topic.**>
@@ -79,6 +97,18 @@ Output Plugin can be used via match directive.
79
97
 
80
98
  ```
81
99
 
100
+ For fluent-plugin-mqtt-io ~> v0.3.0
101
+
102
+ ```
103
+
104
+ <match topic.**>
105
+ @type mqtt
106
+ host 127.0.0.1
107
+ port 1883
108
+ </match>
109
+
110
+ ```
111
+
82
112
  The options are basically the same as Input Plugin except for "format" and "bulk_trans" (only for Input). Additional options for Output Plugin are the following.
83
113
 
84
114
  - time_key: An attribute name used for timestamp field genarated from fluentd time field. Default is nil (omitted).
@@ -93,6 +123,7 @@ If you use different source, e.g. the other MQTT broker, log file and so on, the
93
123
 
94
124
  The topic name or tag name, e.g. "topic", received from an event can not be published without modification because if MQTT input plugin connecting to the identical MQTT broker is used as a source, the same message will become an input repeatedly. In order to support data conversion in single MQTT domain, simple topic rewriting should be supported. Since topic is rewritten using #gsub method, 'pattern' and 'replacement' are the same as #gsub arguments.
95
125
 
126
+ For fluent-plugin-mqtt-io <= v0.2.3
96
127
 
97
128
  ```
98
129
 
@@ -106,6 +137,20 @@ The topic name or tag name, e.g. "topic", received from an event can not be publ
106
137
 
107
138
  ```
108
139
 
140
+ For fluent-plugin-mqtt-io ~> v0.3.0
141
+
142
+ ```
143
+
144
+ <match topic.**>
145
+ @type mqtt
146
+ host 127.0.0.1
147
+ port 1883
148
+ topic_rewrite_pattern '^([\w\/]+)$'
149
+ topic_rewrite_replacement '\1/rewritten'
150
+ </match>
151
+
152
+ ```
153
+
109
154
  You can also use mqtt_buf type which is implemented as Fluent::MqttBufferedOutput.
110
155
 
111
156
  ```
@@ -123,6 +168,25 @@ You can also use mqtt_buf type which is implemented as Fluent::MqttBufferedOutpu
123
168
 
124
169
  ```
125
170
 
171
+ For fluent-plugin-mqtt-io ~> v0.3.0
172
+
173
+ ```
174
+
175
+ <match topic.**>
176
+ @type mqtt
177
+ host 127.0.0.1
178
+ port 1883
179
+ topic_rewrite_pattern '^([\w\/]+)$'
180
+ topic_rewrite_replacement '\1/rewritten'
181
+ # You can specify Buffer Plugin options
182
+ <buffer>
183
+ buffer_type memory
184
+ flush_interval 1s
185
+ </buffer>
186
+ </match>
187
+
188
+ ```
189
+
126
190
  When a plugin implemented as Fluent::BufferedOutput, fluentd stores the received messages into buffers (Fluent::MemoryBuffer is used as default) separated by tag names. Writer Threads emit those stored messages periodically in the specified interval. In MqttBufferedOutput, the stored messages are concatenated with 'bulk_trans_sep' (default: "\t"). This function reduces the number of messages sent via MQTT if data producing interval of sensors are smaller than publish interval (flush_interval). The concatinated messages can be properly handled by Fluent::MqttInput plugin by specifying 'bulk_trans' option.
127
191
 
128
192
  ## Use case examples
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "fluent-plugin-mqtt-io"
7
- spec.version = "0.3.1"
7
+ spec.version = "0.3.3"
8
8
  spec.authors = ["Toyokazu Akiyama"]
9
9
  spec.email = ["toyokazu@gmail.com"]
10
10
 
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.required_ruby_version = '>= 2.2.0'
23
23
 
24
24
  spec.add_dependency 'fluentd', '~> 0.14'
25
- spec.add_dependency "mqtt", "~> 0.4"
25
+ spec.add_dependency "mqtt", "~> 0.5"
26
26
 
27
27
  spec.add_development_dependency "bundler", "~> 1.14"
28
28
  spec.add_development_dependency "rake", "~> 12.0"
@@ -1,54 +1,26 @@
1
1
  require 'fluent/plugin/input'
2
2
  require 'fluent/event'
3
3
  require 'fluent/time'
4
- require 'mqtt'
4
+ require 'fluent/plugin/mqtt_proxy'
5
5
 
6
6
  module Fluent::Plugin
7
7
  class MqttInput < Input
8
+ include MqttProxy
9
+
8
10
  Fluent::Plugin.register_input('mqtt', self)
9
11
 
10
12
  helpers :thread, :compat_parameters, :parser
11
13
 
12
- MQTT_PORT = 1883
13
-
14
- desc 'The address to connect to.'
15
- config_param :host, :string, default: '127.0.0.1'
16
- desc 'The port to connect to.'
17
- config_param :port, :integer, default: MQTT_PORT
18
14
  desc 'The topic to subscribe.'
19
15
  config_param :topic, :string, default: '#'
20
16
  desc 'The format to receive.'
21
17
  config_param :format, :string, default: 'json'
22
- desc 'Specify keep alive interval.'
23
- config_param :keep_alive, :integer, default: 15
24
- desc 'Specify initial interval for reconnection.'
25
- config_param :initial_interval, :integer, default: 1
26
- desc 'Specify increasing ratio of reconnection interval.'
27
- config_param :retry_inc_ratio, :integer, default: 2
28
18
 
29
19
  # bulk_trans is deprecated
30
20
  # multiple entries must be inputted as an Array
31
21
  #config_param :bulk_trans, :bool, default: true
32
22
  #config_param :bulk_trans_sep, :string, default: "\t"
33
23
 
34
- config_section :security, required: false, multi: false do
35
- ### User based authentication
36
- desc 'The username for authentication'
37
- config_param :username, :string, default: nil
38
- desc 'The password for authentication'
39
- config_param :password, :string, default: nil
40
- desc 'Use TLS or not.'
41
- config_param :use_tls, :bool, default: nil
42
- config_section :tls, required: false, multi: true do
43
- desc 'Specify TLS ca file.'
44
- config_param :ca_file, :string, default: nil
45
- desc 'Specify TLS key file.'
46
- config_param :key_file, :string, default: nil
47
- desc 'Specify TLS cert file.'
48
- config_param :cert_file, :string, default: nil
49
- end
50
- end
51
-
52
24
  config_section :monitor, required: false, multi: false do
53
25
  desc 'Record received time into message or not.'
54
26
  config_param :recv_time, :bool, default: false
@@ -59,7 +31,6 @@ module Fluent::Plugin
59
31
  def configure(conf)
60
32
  super
61
33
  configure_parser(conf)
62
- init_retry_interval
63
34
  end
64
35
 
65
36
  def configure_parser(conf)
@@ -68,71 +39,32 @@ module Fluent::Plugin
68
39
  @parser = parser_create(conf: parser_config)
69
40
  end
70
41
 
71
- def init_retry_interval
72
- @retry_interval = @initial_interval
42
+ def start
43
+ super
44
+ start_proxy
73
45
  end
74
46
 
75
- def increment_retry_interval
76
- @retry_interval = @retry_interval * @retry_inc_ratio
47
+ def shutdown
48
+ shutdown_proxy
49
+ super
77
50
  end
78
51
 
79
- def sleep_retry_interval(e, message)
80
- log.error "#{message},#{e.class},#{e.message}"
81
- log.error "Retry in #{@retry_interval} sec"
82
- sleep @retry_interval
83
- increment_retry_interval
52
+ def current_plugin_name
53
+ :in_mqtt
84
54
  end
85
55
 
86
- def start
87
- log.debug "start mqtt #{@host}"
88
- opts = {
89
- host: @host,
90
- port: @port,
91
- keep_alive: @keep_alive
92
- }
93
- opts[:username] = @security.username if @security.respond_to?(:username)
94
- opts[:password] = @security.password if @security.respond_to?(:password)
95
- if @security.respond_to?(:use_tls) && @security.use_tls
96
- opts[:ssl] = @security.use_tls
97
- opts[:ca_file] = @security.tls.ca_file
98
- opts[:cert_file] = @security.tls.cert_file
99
- opts[:key_file] = @security.tls.key_file
100
- end
101
-
102
- # In order to handle Exception raised from reading Thread
103
- # in MQTT::Client caused by network disconnection (during read_byte),
104
- # @connect_thread generates connection.
105
- @client = MQTT::Client.new(opts)
106
- @get_thread = nil
107
- @connect_thread = Thread.new(&method(:connect_loop))
56
+ def after_disconnection
108
57
  end
109
58
 
110
- def connect_loop
111
- while (true)
112
- begin
113
- @get_thread.kill if !@get_thread.nil? && @get_thread.alive?
114
- @client.disconnect if @client.connected?
115
- @client.connect
116
- @client.subscribe(@topic)
117
- @get_thread = Thread.new do
59
+ def after_connection
60
+ if @client.connected?
61
+ @client.subscribe(@topic)
62
+ thread_create(:in_mqtt_get) do
63
+ rescue_disconnection do
118
64
  @client.get do |topic, message|
119
65
  emit(topic, message)
120
66
  end
121
67
  end
122
- init_retry_interval
123
- sleep
124
- rescue MQTT::ProtocolException => e
125
- sleep_retry_interval(e, "Protocol error occurs.")
126
- next
127
- rescue Timeout::Error => e
128
- sleep_retry_interval(e, "Timeout error occurs.")
129
- next
130
- rescue SystemCallError => e
131
- sleep_retry_interval(e, "System call error occurs.")
132
- next
133
- rescue StandardError=> e
134
- sleep_retry_interval(e, "The other error occurs.")
135
- next
136
68
  end
137
69
  end
138
70
  end
@@ -175,11 +107,5 @@ module Fluent::Plugin
175
107
  log.debug_backtrace(e.backtrace)
176
108
  end
177
109
  end
178
-
179
- def shutdown
180
- @get_thread.kill
181
- @connect_thread.kill
182
- @client.disconnect
183
- end
184
110
  end
185
111
  end
@@ -0,0 +1,129 @@
1
+ require 'mqtt'
2
+ module Fluent::Plugin
3
+ module MqttProxy
4
+ MQTT_PORT = 1883
5
+
6
+ def self.included(base)
7
+ base.helpers :timer
8
+
9
+ base.desc 'The address to connect to.'
10
+ base.config_param :host, :string, default: '127.0.0.1'
11
+ base.desc 'The port to connect to.'
12
+ base.config_param :port, :integer, default: MQTT_PORT
13
+ base.desc 'Specify keep alive interval.'
14
+ base.config_param :keep_alive, :integer, default: 15
15
+ base.desc 'Specify initial connection retry interval.'
16
+ base.config_param :initial_interval, :integer, default: 1
17
+ base.desc 'Specify increasing ratio of connection retry interval.'
18
+ base.config_param :retry_inc_ratio, :integer, default: 2
19
+ base.desc 'Specify maximum connection retry interval.'
20
+ base.config_param :max_retry_interval, :integer, default: 300
21
+
22
+ base.config_section :security, required: false, multi: false do
23
+ ### User based authentication
24
+ base.desc 'The username for authentication'
25
+ base.config_param :username, :string, default: nil
26
+ base.desc 'The password for authentication'
27
+ base.config_param :password, :string, default: nil
28
+ base.desc 'Use TLS or not.'
29
+ base.config_param :use_tls, :bool, default: nil
30
+ base.config_section :tls, required: false, multi: true do
31
+ base.desc 'Specify TLS ca file.'
32
+ base.config_param :ca_file, :string, default: nil
33
+ base.desc 'Specify TLS key file.'
34
+ base.config_param :key_file, :string, default: nil
35
+ base.desc 'Specify TLS cert file.'
36
+ base.config_param :cert_file, :string, default: nil
37
+ end
38
+ end
39
+ end
40
+
41
+ class MqttProxyError
42
+ end
43
+
44
+ def current_plugin_name
45
+ # should be implemented
46
+ end
47
+
48
+ def start_proxy
49
+ log.debug "start mqtt proxy for #{current_plugin_name}"
50
+ log.debug "start to connect mqtt broker #{@host}:#{@port}"
51
+ opts = {
52
+ host: @host,
53
+ port: @port,
54
+ keep_alive: @keep_alive
55
+ }
56
+ opts[:username] = @security.username if @security.respond_to?(:username)
57
+ opts[:password] = @security.password if @security.respond_to?(:password)
58
+ if @security.respond_to?(:use_tls) && @security.use_tls
59
+ opts[:ssl] = @security.use_tls
60
+ opts[:ca_file] = @security.tls.ca_file
61
+ opts[:cert_file] = @security.tls.cert_file
62
+ opts[:key_file] = @security.tls.key_file
63
+ end
64
+
65
+ init_retry_interval
66
+ @client_mutex = Mutex.new
67
+ @client = MQTT::Client.new(opts)
68
+ connect
69
+ end
70
+
71
+ def shutdown_proxy
72
+ @client.disconnect
73
+ end
74
+
75
+ def init_retry_interval
76
+ @retry_interval = @initial_interval
77
+ end
78
+
79
+ def increment_retry_interval
80
+ return @retry_interval if @retry_interval >= @max_retry_interval
81
+ @retry_interval = @retry_interval * @retry_inc_ratio
82
+ end
83
+
84
+ def retry_connect(e, message)
85
+ log.error "#{message},#{e.class},#{e.message}"
86
+ log.error "Retry in #{@retry_interval} sec"
87
+ timer_execute("#{current_plugin_name}_connect".to_sym, @retry_interval, repeat: false, &method(:connect))
88
+ increment_retry_interval
89
+ after_disconnection
90
+ @client.disconnect if @client.connected?
91
+ end
92
+
93
+ def after_disconnection
94
+ # should be implemented
95
+ end
96
+
97
+ def rescue_disconnection(*block)
98
+ begin
99
+ yield *block
100
+ rescue MQTT::ProtocolException => e
101
+ # TODO:
102
+ # Currently MQTT::ProtocolException cannot be caught during @client.get
103
+ # and @client.publish. The reason must be investigated...
104
+ retry_connect(e, "Protocol error occurs.")
105
+ rescue Timeout::Error => e
106
+ retry_connect(e, "Timeout error occurs.")
107
+ rescue SystemCallError => e
108
+ retry_connect(e, "System call error occurs.")
109
+ rescue StandardError=> e
110
+ retry_connect(e, "The other error occurs.")
111
+ end
112
+ end
113
+
114
+ def after_connection
115
+ # should be implemented
116
+ end
117
+
118
+ def connect
119
+ @client_mutex.lock
120
+ rescue_disconnection do
121
+ @client.connect
122
+ log.debug "connected to mqtt broker #{@host}:#{@port} for #{current_plugin_name}"
123
+ init_retry_interval
124
+ end
125
+ @client_mutex.unlock
126
+ after_connection
127
+ end
128
+ end
129
+ end
@@ -1,48 +1,20 @@
1
1
  require 'fluent/plugin/output'
2
2
  require 'fluent/event'
3
3
  require 'fluent/time'
4
- require 'mqtt'
4
+ require 'fluent/plugin/mqtt_proxy'
5
5
 
6
6
  module Fluent::Plugin
7
7
  class MqttOutput < Output
8
+ include MqttProxy
9
+
8
10
  Fluent::Plugin.register_output('mqtt', self)
9
11
 
10
12
  helpers :compat_parameters, :formatter, :inject
11
13
 
12
- MQTT_PORT = 1883
13
-
14
- desc 'The address to connect to.'
15
- config_param :host, :string, default: '127.0.0.1'
16
- desc 'The port to connect to.'
17
- config_param :port, :integer, default: MQTT_PORT
18
- desc 'MQTT keep alive interval.'
19
- config_param :keep_alive, :integer, default: 15
20
14
  desc 'Topic rewrite matching pattern.'
21
15
  config_param :topic_rewrite_pattern, :string, default: nil
22
16
  desc 'Topic rewrite replacement string.'
23
17
  config_param :topic_rewrite_replacement, :string, default: nil
24
- desc 'Initial retry interval.'
25
- config_param :initial_interval, :integer, default: 1
26
- desc 'Increasing ratio of retry interval.'
27
- config_param :retry_inc_ratio, :integer, default: 2
28
-
29
- config_section :security, required: false, multi: false do
30
- ### User based authentication
31
- desc 'The username for authentication'
32
- config_param :username, :string, default: nil
33
- desc 'The password for authentication'
34
- config_param :password, :string, default: nil
35
- desc 'Use TLS or not.'
36
- config_param :use_tls, :bool, default: nil
37
- config_section :tls, required: false, multi: true do
38
- desc 'TLS ca file.'
39
- config_param :ca_file, :string, default: nil
40
- desc 'TLS key file.'
41
- config_param :key_file, :string, default: nil
42
- desc 'TLS cert file.'
43
- config_param :cert_file, :string, default: nil
44
- end
45
- end
46
18
 
47
19
  config_section :monitor, required: false, multi: false do
48
20
  desc 'Recording send time for monitoring.'
@@ -60,22 +32,6 @@ module Fluent::Plugin
60
32
  formatter_config = conf.elements(name: 'format').first
61
33
  @formatter = formatter_create(conf: formatter_config)
62
34
  @has_buffer_section = conf.elements(name: 'buffer').size > 0
63
- init_retry_interval
64
- end
65
-
66
- def init_retry_interval
67
- @retry_interval = @initial_interval
68
- end
69
-
70
- def increment_retry_interval
71
- @retry_interval = @retry_interval * @retry_inc_ratio
72
- end
73
-
74
- def sleep_retry_interval(e, message)
75
- log.error "#{message},#{e.class},#{e.message}"
76
- log.error "Retry in #{@retry_interval} sec"
77
- sleep @retry_interval
78
- increment_retry_interval
79
35
  end
80
36
 
81
37
  def rewrite_tag(tag)
@@ -94,89 +50,18 @@ module Fluent::Plugin
94
50
  # Open sockets or files here.
95
51
  def start
96
52
  super
97
-
98
- log.debug "start to connect mqtt broker #{@host}:#{@port}"
99
- opts = {
100
- host: @host,
101
- port: @port,
102
- keep_alive: @keep_alive
103
- }
104
- opts[:username] = @security.username if @security.respond_to?(:username)
105
- opts[:password] = @security.password if @security.respond_to?(:password)
106
- if @security.respond_to?(:use_tls) && @security.use_tls
107
- opts[:ssl] = @security.use_tls
108
- opts[:ca_file] = @security.tls.ca_file
109
- opts[:cert_file] = @security.tls.cert_file
110
- opts[:key_file] = @security.tls.key_file
111
- end
112
- # In order to handle Exception raised from reading Thread
113
- # in MQTT::Client caused by network disconnection (during read_byte),
114
- # @connect_thread generates connection.
115
- @client_mutex = Mutex.new
116
- @client = MQTT::Client.new(opts)
117
- connect_loop
53
+ start_proxy
118
54
  end
119
55
 
120
56
  # This method is called when shutting down.
121
57
  # Shutdown the thread and close sockets or files here.
122
58
  def shutdown
59
+ shutdown_proxy
123
60
  super
124
-
125
- @client.disconnect
126
61
  end
127
62
 
128
- def connect_loop
129
- while (true)
130
- @client_mutex.lock
131
- begin
132
- @client.disconnect if @client.connected?
133
- @client.connect
134
- init_retry_interval
135
- rescue MQTT::ProtocolException => e
136
- sleep_retry_interval(e, "Protocol error occurs.")
137
- @client_mutex.unlock
138
- next
139
- rescue Timeout::Error => e
140
- sleep_retry_interval(e, "Timeout error occurs.")
141
- @client_mutex.unlock
142
- next
143
- rescue SystemCallError => e
144
- sleep_retry_interval(e, "System call error occurs.")
145
- @client_mutex.unlock
146
- next
147
- rescue StandardError=> e
148
- sleep_retry_interval(e, "The other error occurs.")
149
- @client_mutex.unlock
150
- next
151
- end
152
- @client_mutex.unlock
153
- break
154
- end
155
- end
156
-
157
- def publish_error_handler
158
- while(true)
159
- begin
160
- yield
161
- rescue MQTT::ProtocolException => e
162
- sleep_retry_interval(e, "Protocol error occurs.")
163
- connect_loop
164
- next
165
- rescue Timeout::Error => e
166
- sleep_retry_interval(e, "Timeout error occurs.")
167
- connect_loop
168
- next
169
- rescue SystemCallError => e
170
- sleep_retry_interval(e, "System call error occurs.")
171
- connect_loop
172
- next
173
- rescue StandardError=> e
174
- sleep_retry_interval(e, "The other error occurs.")
175
- connect_loop
176
- next
177
- end
178
- break
179
- end
63
+ def current_plugin_name
64
+ :out_mqtt
180
65
  end
181
66
 
182
67
  def add_send_time(record)
@@ -192,8 +77,8 @@ module Fluent::Plugin
192
77
  if es.class == Fluent::OneEventStream
193
78
  es = inject_values_to_event_stream(tag, es)
194
79
  es.each do |time, record|
195
- log.debug "#{rewrite_tag(tag)}, #{add_send_time(record)}"
196
- publish_error_handler do
80
+ log.debug "#{rewrite_tag(tag)}, #{time}, #{add_send_time(record)}"
81
+ rescue_disconnection do
197
82
  @client.publish(rewrite_tag(tag), @formatter.format(tag, time, add_send_time(record)))
198
83
  end
199
84
  end
@@ -201,10 +86,10 @@ module Fluent::Plugin
201
86
  es = inject_values_to_event_stream(tag, es)
202
87
  array = []
203
88
  es.each do |time, record|
204
- log.debug "#{rewrite_tag(tag)}, #{add_send_time(record)}"
89
+ log.debug "#{rewrite_tag(tag)}, #{time}, #{add_send_time(record)}"
205
90
  array << add_send_time(record)
206
91
  end
207
- publish_error_handler do
92
+ rescue_disconnection do
208
93
  @client.publish(rewrite_tag(tag), @formatter.format(tag, Fluent::EventTime.now, array))
209
94
  end
210
95
  end
@@ -215,11 +100,22 @@ module Fluent::Plugin
215
100
  publish_event_stream(tag, es)
216
101
  end
217
102
 
103
+ def format(tag, time, record)
104
+ [tag, time, record].to_msgpack
105
+ end
106
+
107
+ def formatted_to_msgpack_binary
108
+ true
109
+ end
110
+
218
111
  def write(chunk)
219
112
  return if chunk.empty?
220
- tag = chunk.metadata.tag
221
-
222
- publish_event_stream(tag, es)
113
+ chunk.each do |tag, time, record|
114
+ rescue_disconnection do
115
+ log.debug "#{rewrite_tag(rewrite_tag(tag))}, #{time}, #{add_send_time(record)}"
116
+ @client.publish(rewrite_tag(tag), @formatter.format(tag, time, add_send_time(record)))
117
+ end
118
+ end
223
119
  end
224
120
  end
225
121
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-mqtt-io
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Toyokazu Akiyama
8
8
  autorequire:
9
9
  bindir: []
10
10
  cert_chain: []
11
- date: 2017-05-07 00:00:00.000000000 Z
11
+ date: 2017-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.4'
33
+ version: '0.5'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0.4'
40
+ version: '0.5'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -96,6 +96,7 @@ files:
96
96
  - Rakefile
97
97
  - fluent-plugin-mqtt-io.gemspec
98
98
  - lib/fluent/plugin/in_mqtt.rb
99
+ - lib/fluent/plugin/mqtt_proxy.rb
99
100
  - lib/fluent/plugin/out_mqtt.rb
100
101
  - test/helper.rb
101
102
  - test/plugin/test_in_mqtt.rb