mqtt-sub_handler 0.1.6.6 → 0.1.6.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mqtt/base_handler.rb +36 -21
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9be8cc94d063f20f4e602ca44c33e1f063fcd8db
|
4
|
+
data.tar.gz: b115b3aa01cdb8aceab2ba442d1e8748c25ce3e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18305fa0dbabdaea4762c0b53adec091bd0db67f06ef23aca414ab136ccc35e50c26641f5d21cd6d70554a6b213f87295b23ceaab1f07d9ff04f0e17fef53770
|
7
|
+
data.tar.gz: 8b1aa38aad47777c42538ef19d17db3cf9cd49259d177863664d8ae561406d0691a7e80b774e1f6dd5f6d09d8ce6c8bda7a23a933a2f68b593e29daf857aa7fe
|
data/lib/mqtt/base_handler.rb
CHANGED
@@ -161,7 +161,28 @@ module MQTT
|
|
161
161
|
end
|
162
162
|
private :ensure_clean_exit
|
163
163
|
|
164
|
+
def attempt_packet_publish()
|
165
|
+
until @packetQueue.empty? do
|
166
|
+
h = nil;
|
167
|
+
@packetQueueMutex.synchronize {
|
168
|
+
h = @packetQueue[0];
|
169
|
+
}
|
170
|
+
Timeout.timeout(3) {
|
171
|
+
if(h[:type] == :sub)
|
172
|
+
@mqtt.subscribe(h[:topic] => h[:qos]);
|
173
|
+
elsif(h[:type] == :pub)
|
174
|
+
@mqtt.publish(h[:topic], h[:data], h[:retain], h[:qos]);
|
175
|
+
end
|
176
|
+
}
|
177
|
+
@packetQueueMutex.synchronize {
|
178
|
+
@packetQueue.shift();
|
179
|
+
}
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
164
183
|
def mqtt_push_thread
|
184
|
+
@push_error_count = 0;
|
185
|
+
|
165
186
|
loop do
|
166
187
|
@packetQueueMutex.synchronize {
|
167
188
|
@publisherThreadWaiting = true;
|
@@ -177,27 +198,19 @@ module MQTT
|
|
177
198
|
next unless @connected
|
178
199
|
|
179
200
|
begin
|
180
|
-
|
181
|
-
h = nil;
|
182
|
-
@packetQueueMutex.synchronize {
|
183
|
-
h = @packetQueue[0];
|
184
|
-
}
|
185
|
-
Timeout.timeout(3) {
|
186
|
-
if(h[:type] == :sub)
|
187
|
-
@mqtt.subscribe(h[:topic] => h[:qos]);
|
188
|
-
elsif(h[:type] == :pub)
|
189
|
-
@mqtt.publish(h[:topic], h[:data], h[:retain], h[:qos]);
|
190
|
-
end
|
191
|
-
}
|
192
|
-
@packetQueueMutex.synchronize {
|
193
|
-
@packetQueue.shift();
|
194
|
-
}
|
195
|
-
end
|
201
|
+
attempt_packet_publish();
|
196
202
|
rescue MQTT::Exception, SocketError, SystemCallError, Timeout::Error => e
|
197
|
-
|
198
|
-
|
203
|
+
x_loge("Push error!");
|
204
|
+
x_loge(e.inspect);
|
199
205
|
|
200
|
-
|
206
|
+
@push_error_count += 1;
|
207
|
+
if(@push_error_count >= 10)
|
208
|
+
@mqtt.disconnect();
|
209
|
+
end
|
210
|
+
|
211
|
+
sleep 0.5
|
212
|
+
else
|
213
|
+
@push_error_count = 0;
|
201
214
|
end
|
202
215
|
end
|
203
216
|
|
@@ -284,11 +297,13 @@ module MQTT
|
|
284
297
|
# @example Starting the handler
|
285
298
|
# mqtt = MQTT::SubHandler.new('mqtt.eclipse.org');
|
286
299
|
# mqtt = MQTT::SubHandler.new(MQTT::Client.new("Your.Client.Opts"))
|
287
|
-
def initialize(mqttClient, logger: nil)
|
300
|
+
def initialize(mqttClient, logger: nil, **extra_opts)
|
288
301
|
@callbackList = Array.new();
|
289
302
|
if mqttClient.is_a? String
|
290
303
|
@mqtt = MQTT::Client.new(mqttClient);
|
291
304
|
@mqtt.clean_session = false;
|
305
|
+
|
306
|
+
@mqttWasStartedClean = true if extra_opts[:client_id].nil?
|
292
307
|
else
|
293
308
|
@mqtt = mqttClient;
|
294
309
|
end
|
@@ -300,7 +315,7 @@ module MQTT
|
|
300
315
|
@connected = false;
|
301
316
|
@reconnectCount = 0;
|
302
317
|
|
303
|
-
@mqtt.client_id ||= MQTT::Client.generate_client_id("MQTT_Sub_", 8);
|
318
|
+
@mqtt.client_id ||= extra_opts[:client_id] || MQTT::Client.generate_client_id("MQTT_Sub_", 8);
|
304
319
|
|
305
320
|
@packetQueue = Array.new();
|
306
321
|
@packetQueueMutex = Mutex.new();
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mqtt-sub_handler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.6.
|
4
|
+
version: 0.1.6.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Xasin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mqtt
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: json
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '2.2'
|
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: '
|
40
|
+
version: '2.2'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: xasin-logger
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|