fluent-plugin-mqtt-io 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: cc6dec8983c390053d834987c88e0270eb667698
4
- data.tar.gz: 62e1f5a0fea5a8118828ed0f06ec267434b32b51
3
+ metadata.gz: b92961979e0e7c98b9bf30ff4bac39699e05a051
4
+ data.tar.gz: 2eb7b4a5bcaa0bf547b14a450a5b9d22476b7b3f
5
5
  SHA512:
6
- metadata.gz: caa412b890d75a0c261e3a5422c827bb4d0d81e7214b30829daaf6bbc68cbd2cbd511d64d963b0cb3ba4b772c7c32c107bfc22d092c6b754a2f80a4514f4062d
7
- data.tar.gz: 342e79e3cb772b44857e1012c710d8b27ecec17a920f1dda6af37f49a9aed8163b472c9ccda28131de6d59cc691e471c93de344f3faa9dccd43038d00409a9f1
6
+ metadata.gz: 5506fc16e2274390d4d62c7afa05703b84272f1b81f35d118da2f6dea29ab09d3d41bffa080c2ab5317e87edd9c296b74aead52765c88ce807d6ab92ff69ba12
7
+ data.tar.gz: a20ee1541d43cd73cc5187659a2e9b8213751a9b8847a6d0698f1744ceb34685d3d394f2ceb6dd06ad61a5c58831be3b1a4a0f273d3d236363b075ea112628c4
data/README.md CHANGED
@@ -53,6 +53,7 @@ The default MQTT topic is "#". Configurable options are the following:
53
53
  - bulk_trans_sep: A message separator for bulk transfer. The default separator is "\t".
54
54
  - username: User name for authentication
55
55
  - password: Password for authentication
56
+ - keep_alive: An interval of sending keep alive packet (default 15 sec)
56
57
  - ssl: set true if you want to use SSL/TLS. If set to true, the following parameter must be provided
57
58
  - ca_file: CA certificate file path
58
59
  - key_file: private key file path
@@ -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.1.1"
7
+ spec.version = "0.1.2"
8
8
  spec.authors = ["Toyokazu Akiyama"]
9
9
  spec.email = ["toyokazu@gmail.com"]
10
10
 
@@ -10,6 +10,7 @@ module Fluent
10
10
  config_param :bulk_trans_sep, :string, :default => "\t"
11
11
  config_param :username, :string, :default => nil
12
12
  config_param :password, :string, :default => nil
13
+ config_param :keep_alive, :integer, :default => 15
13
14
  config_param :ssl, :bool, :default => nil
14
15
  config_param :ca_file, :string, :default => nil
15
16
  config_param :key_file, :string, :default => nil
@@ -31,14 +32,31 @@ module Fluent
31
32
  @port ||= conf['port']
32
33
  @username ||= conf['username']
33
34
  @password ||= conf['password']
35
+ @keep_alive ||= conf['keep_alive']
34
36
  configure_parser(conf)
35
- @reconn_interval = 2
37
+ init_retry_interval
36
38
  end
37
39
 
38
40
  def configure_parser(conf)
39
41
  @parser = Plugin.new_parser(conf['format'])
40
42
  @parser.configure(conf)
41
43
  end
44
+
45
+ def init_retry_interval
46
+ @retry_interval = 1
47
+ end
48
+
49
+ def increment_retry_interval
50
+ @retry_interval = @retry_interval * 2
51
+ end
52
+
53
+ def sleep_retry_interval(e, message)
54
+ $log.debug "#{message}"
55
+ $log.debug "#{e.class}: #{e.message}"
56
+ $log.debug "Retry in #{@retry_interval} sec"
57
+ sleep @retry_interval
58
+ increment_retry_interval
59
+ end
42
60
 
43
61
  def start
44
62
  $log.debug "start mqtt #{@bind}"
@@ -46,7 +64,8 @@ module Fluent
46
64
  host: @bind,
47
65
  port: @port,
48
66
  username: @username,
49
- password: @password
67
+ password: @password,
68
+ keep_alive: @keep_alive
50
69
  }
51
70
  opts[:ssl] = @ssl if @ssl
52
71
  opts[:ca_file] = @ca_file if @ca_file
@@ -69,22 +88,20 @@ module Fluent
69
88
  emit(topic, message)
70
89
  end
71
90
  end
72
- @reconn_interval = 2
91
+ init_retry_interval
73
92
  sleep
74
- rescue MQTT::ProtocolException => pe
75
- $log.debug "Handling #{pe.class}: #{pe.message}"
93
+ rescue MQTT::ProtocolException => e
94
+ sleep_retry_interval(e, "Protocol error occurs.")
95
+ next
96
+ rescue Timeout::Error => e
97
+ sleep_retry_interval(e, "Timeout error occurs.")
76
98
  next
77
- rescue Timeout::Error => te
78
- $log.debug "Handling #{te.class}: #{te.message}"
99
+ rescue SystemCallError => e
100
+ sleep_retry_interval(e, "System call error occurs.")
79
101
  next
80
- rescue Errno::ECONNREFUSED => ce
81
- $log.debug "Server seems to be down... Retry in #{@reconn_interval} sec #{ce.class}: #{ce.message}"
82
- sleep @reconn_interval
83
- @reconn_interval = @reconn_interval * 2
102
+ rescue StandardError=> e
103
+ sleep_retry_interval(e, "The other error occurs.")
84
104
  next
85
- rescue => oe
86
- $log.debug "Other Exception #{oe.class}: #{oe.message}"
87
- exit 1
88
105
  end
89
106
  end
90
107
  end
@@ -8,6 +8,7 @@ module Fluent
8
8
  base.config_param :bind, :string, :default => '127.0.0.1'
9
9
  base.config_param :username, :string, :default => nil
10
10
  base.config_param :password, :string, :default => nil
11
+ base.config_param :keep_alive, :integer, :default => 15
11
12
  base.config_param :ssl, :bool, :default => nil
12
13
  base.config_param :ca_file, :string, :default => nil
13
14
  base.config_param :key_file, :string, :default => nil
@@ -32,11 +33,29 @@ module Fluent
32
33
  @port ||= conf['port']
33
34
  @username ||= conf['username']
34
35
  @password ||= conf['password']
36
+ @keep_alive ||= conf['keep_alive']
35
37
  @time_key ||= conf['time_key']
36
38
  @time_format ||= conf['time_format']
37
39
  @topic_rewrite_pattern ||= conf['topic_rewrite_pattern']
38
40
  @topic_rewrite_replacement ||= conf['topic_rewrite_replacement']
39
41
  @bulk_trans_sep ||= conf['bulk_trans_sep']
42
+ init_retry_interval
43
+ end
44
+
45
+ def init_retry_interval
46
+ @retry_interval = 1
47
+ end
48
+
49
+ def increment_retry_interval
50
+ @retry_interval = @retry_interval * 2
51
+ end
52
+
53
+ def sleep_retry_interval(e, message)
54
+ $log.debug "#{message}"
55
+ $log.debug "#{e.class}: #{e.message}"
56
+ $log.debug "Retry in #{@retry_interval} sec"
57
+ sleep @retry_interval
58
+ increment_retry_interval
40
59
  end
41
60
 
42
61
  # This method is called when starting.
@@ -49,7 +68,8 @@ module Fluent
49
68
  host: @bind,
50
69
  port: @port,
51
70
  username: @username,
52
- password: @password
71
+ password: @password,
72
+ keep_alive: @keep_alive
53
73
  }
54
74
  opts[:ssl] = @ssl if @ssl
55
75
  opts[:ca_file] = @ca_file if @ca_file
@@ -64,12 +84,19 @@ module Fluent
64
84
  begin
65
85
  @client.disconnect if @client.connected?
66
86
  @client.connect
87
+ init_retry_interval
67
88
  sleep
68
- rescue MQTT::ProtocolException => pe
69
- $log.debug "Handling #{pe.class}: #{pe.message}"
89
+ rescue MQTT::ProtocolException => e
90
+ sleep_retry_interval(e, "Protocol error occurs.")
91
+ next
92
+ rescue Timeout::Error => e
93
+ sleep_retry_interval(e, "Timeout error occurs.")
94
+ next
95
+ rescue SystemCallError => e
96
+ sleep_retry_interval(e, "System call error occurs.")
70
97
  next
71
- rescue Timeout::Error => te
72
- $log.debug "Handling #{te.class}: #{te.message}"
98
+ rescue StandardError=> e
99
+ sleep_retry_interval(e, "The other error occurs.")
73
100
  next
74
101
  end
75
102
  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.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Toyokazu Akiyama
8
8
  autorequire:
9
9
  bindir: []
10
10
  cert_chain: []
11
- date: 2016-01-01 00:00:00.000000000 Z
11
+ date: 2016-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd