redis-stream 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/redis/stream/client.rb +51 -61
- data/lib/redis/stream/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c68feb94f854987274b877134586cc49f146621d1bca1463dc7727c3d3330890
|
4
|
+
data.tar.gz: 3d0217743ed703c37bbe51c8fa69c89c0ee58749589d2edd3241c5950dae3447
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b02a972747cf975360ceda206121f0dfd6e2dd12764eb1c7b90114785b932100b089629f19c7a09af5d49a0e648c775fd84400c2183cc0cdd5c0e2e2b2cf5de
|
7
|
+
data.tar.gz: 8816191f416792538278642d832d497e10cdcb3f4396ce9440825bad722a53a132111af3054f3d4289f5a0368726c7447d67e59c251f519de8a4ba7871cf34f1
|
data/Gemfile.lock
CHANGED
data/lib/redis/stream/client.rb
CHANGED
@@ -80,18 +80,19 @@ class Redis
|
|
80
80
|
# no passthrough variable here. The passthrough is available in the start method
|
81
81
|
def add(data = {}, options = {})
|
82
82
|
raise "Client isn't running" unless @state.eql?(Redis::Stream::State::RUNNING)
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
83
|
+
add_id = nil
|
84
|
+
OpenTracing.start_active_span('add') do |scope|
|
85
|
+
default_options = {"to" => "*", "group" => "*", "type" => Redis::Stream::Type::ACTION, "cache_key" => nil, "tracer" => nil}
|
86
|
+
options = default_options.merge(options)
|
87
|
+
|
88
|
+
type = options["type"]
|
89
|
+
to = options["to"]
|
90
|
+
group = options["group"]
|
91
|
+
payload = build_payload(data, options)
|
92
|
+
add_id = @redis.xadd(@stream, payload)
|
93
|
+
|
94
|
+
@logger.info("#{@consumer_id} - send to '#{to}' in group '#{group}' with id '#{add_id}' of type '#{type}'")
|
95
|
+
end
|
95
96
|
add_id
|
96
97
|
end
|
97
98
|
|
@@ -202,9 +203,6 @@ class Redis
|
|
202
203
|
end
|
203
204
|
end
|
204
205
|
|
205
|
-
def trace_error(operation_name, span = nil)
|
206
|
-
trace(operation_name, span)
|
207
|
-
end
|
208
206
|
private
|
209
207
|
|
210
208
|
def build_payload(data, options)
|
@@ -304,61 +302,53 @@ class Redis
|
|
304
302
|
# @param [Boolean] async return the message if synchronous else call handle_incoming
|
305
303
|
# @param [Boolean] passthrough Receive all messages also the ones intended for other consumers
|
306
304
|
def read_next_message_from_stream(async = true, passthrough = false)
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
305
|
+
if @state == Redis::Stream::State::RUNNING
|
306
|
+
result = @redis.xread(@stream, @lastid, block: 1000, count: 1) if @group.nil?
|
307
|
+
result = @redis.xreadgroup(@group, @consumer_id, @stream, '>', block: 1000, count: 1) if @group
|
308
|
+
|
309
|
+
unless result.empty?
|
310
|
+
id, data_out = result[@stream][0]
|
311
|
+
ack_count = @redis.xack(@stream, @group, id) if @group
|
312
|
+
|
313
|
+
tracer_data = JSON.parse(data_out["tracer"])
|
314
|
+
unless tracer_data.nil? || tracer_data.empty?
|
315
|
+
#trace_scope.span.log_kv('has_tracer' => true)
|
316
|
+
tracer_span = OpenTracing.extract(OpenTracing::FORMAT_TEXT_MAP, tracer_data)
|
317
|
+
data_out["tracer"] = OpenTracing.start_span(@consumer_id, child_of: tracer_span)
|
318
|
+
end
|
320
319
|
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
320
|
+
begin
|
321
|
+
data_out["payload"] = JSON.parse(data_out["payload"])
|
322
|
+
rescue Exception => e
|
323
|
+
@logger.error("#{@consumer_id} error parsing payload: #{e.message}")
|
324
|
+
end
|
326
325
|
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
# unless passthrough
|
331
|
-
# #@logger.info("#{@consumer_id} - ignoring self")
|
332
|
-
# return false
|
333
|
-
# end
|
334
|
-
# end
|
335
|
-
|
336
|
-
if data_out["from"].eql?(@consumer_id)
|
337
|
-
return false
|
338
|
-
end
|
326
|
+
if data_out["from"].eql?(@consumer_id)
|
327
|
+
return false
|
328
|
+
end
|
339
329
|
|
340
|
-
|
341
|
-
|
342
|
-
|
330
|
+
unless (data_out["to"].nil? || data_out["to"].eql?('') || data_out["to"].eql?('*') || data_out["to"].eql?(@consumer_id)) &&
|
331
|
+
(data_out["to_group"].nil? || data_out["to_group"].eql?('') || data_out["to_group"].eql?('*') || data_out["to_group"].eql?(@group))
|
332
|
+
@logger.info("#{@consumer_id} - ignoring message from '#{data_out["from"]}' to '#{data_out["to"]}-#{data_out["to_group"]}'")
|
343
333
|
|
344
|
-
|
345
|
-
|
334
|
+
return false
|
335
|
+
end
|
346
336
|
|
347
|
-
|
337
|
+
@logger.info("#{@consumer_id} - received from '#{data_out["from"]}' of type '#{data_out['type']}' to '#{data_out["to"]}' in group '#{data_out["to_group"]}' with message id '#{id}' - with ack #{ack_count}")
|
348
338
|
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
339
|
+
if data_out["type"].eql?(Redis::Stream::Type::PING)
|
340
|
+
add(data_out["payload"].to_s, "to" => data_out["from"], "group" => "*", "type" => Redis::Stream::Type::PONG)
|
341
|
+
return false
|
342
|
+
end
|
353
343
|
|
354
|
-
|
355
|
-
|
356
|
-
|
344
|
+
if data_out["type"].eql?(Redis::Stream::Type::PONG)
|
345
|
+
return false
|
346
|
+
end
|
357
347
|
|
358
|
-
|
359
|
-
|
348
|
+
return data_out unless async
|
349
|
+
handle_incoming(data_out)
|
350
|
+
end
|
360
351
|
end
|
361
|
-
end
|
362
352
|
rescue Exception => e
|
363
353
|
return false
|
364
354
|
end
|
data/lib/redis/stream/version.rb
CHANGED