kafkr 0.13.0 → 0.18.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exe/kafkr-consumer +1 -1
- data/lib/kafkr/consumer.rb +8 -10
- data/lib/kafkr/log.rb +22 -20
- data/lib/kafkr/message_broker.rb +8 -6
- data/lib/kafkr/producer.rb +2 -0
- data/lib/kafkr/version.rb +1 -1
- data/lib/kafkr.rb +1 -10
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa40dd04299dd0592d9d917e32693c1a8cbd10d25cc9678cdca44413256a0de6
|
4
|
+
data.tar.gz: 815f89d3916c61802215e1441f4d54701a278e0715c8b66686302aa7c7334764
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb51cb0b42d11a6f701dae3ea46fd520c46cbd9c8af20e6040c1f577162eff484d8dd7d9c9a783de60fcfc1250650cbec2ab22aaa8ff6d2481dc5defc57d6714
|
7
|
+
data.tar.gz: 454bbcf8b06713fdac04cff7abcf0d57bbec78fc4b85747e61217d8594fc2cb445dac357c6bc89b6acb4ca047e874d6cfb86060b6cfb30ea7aee03fe68d0508a
|
data/exe/kafkr-consumer
CHANGED
data/lib/kafkr/consumer.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require "socket"
|
1
|
+
require "socket"
|
2
2
|
require "timeout"
|
3
3
|
require "ostruct"
|
4
4
|
require "fileutils"
|
@@ -19,8 +19,8 @@ module Kafkr
|
|
19
19
|
FileUtils.mkdir_p "./.kafkr"
|
20
20
|
@configuration ||= OpenStruct.new
|
21
21
|
@configuration.host = ENV.fetch("KAFKR_HOST", "localhost")
|
22
|
-
@configuration.port = ENV.fetch("KAFKR_PORT",
|
23
|
-
@configuration.timeout = ENV.fetch("KAFKR_CONSUMER_TIMEOUT",
|
22
|
+
@configuration.port = ENV.fetch("KAFKR_PORT", 4000)
|
23
|
+
@configuration.timeout = ENV.fetch("KAFKR_CONSUMER_TIMEOUT", 300)
|
24
24
|
@configuration.suggest_handlers = false
|
25
25
|
@configuration
|
26
26
|
end
|
@@ -160,16 +160,13 @@ module Kafkr
|
|
160
160
|
received_message = socket.gets
|
161
161
|
raise LostConnection if received_message.nil?
|
162
162
|
received_message = Kafkr::Encryptor.new.decrypt(received_message.chomp)
|
163
|
-
if
|
164
|
-
|
165
|
-
return payload if payload
|
166
|
-
end
|
163
|
+
payload = yield received_message, sync_uid if block_given?
|
164
|
+
return payload
|
167
165
|
end
|
168
166
|
end
|
169
167
|
rescue Timeout::Error, LostConnection, Errno::ECONNREFUSED
|
170
168
|
attempt += 1
|
171
169
|
wait_time = backoff_time(attempt)
|
172
|
-
puts "Attempt #{attempt}: Retrying in #{wait_time} seconds..."
|
173
170
|
sleep(wait_time)
|
174
171
|
retry
|
175
172
|
rescue Interrupt
|
@@ -182,8 +179,9 @@ module Kafkr
|
|
182
179
|
def listen
|
183
180
|
attempt = 0
|
184
181
|
loop do
|
185
|
-
listen_for("dummy", ->(msg) {
|
186
|
-
|
182
|
+
listen_for("dummy", ->(msg) { }) do |message|
|
183
|
+
Kafkr.log ">> #{message}"
|
184
|
+
dispatch_to_handlers(message)
|
187
185
|
end
|
188
186
|
end
|
189
187
|
end
|
data/lib/kafkr/log.rb
CHANGED
@@ -35,27 +35,28 @@ module Kafkr
|
|
35
35
|
@broker.add_subscriber(client)
|
36
36
|
|
37
37
|
Thread.new do
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
uuid, message_content = extract_uuid(message)
|
50
|
-
if uuid && message_content
|
51
|
-
@broker.broadcast(message_content)
|
38
|
+
|
39
|
+
|
40
|
+
begin
|
41
|
+
|
42
|
+
loop do
|
43
|
+
encrypted_message = client.gets
|
44
|
+
if encrypted_message.nil?
|
45
|
+
@broker.last_sent.delete(client)
|
46
|
+
client.close
|
47
|
+
@broker.subscribers.delete(client)
|
48
|
+
break
|
52
49
|
else
|
53
|
-
|
50
|
+
decryptor = Kafkr::Encryptor.new
|
51
|
+
message = decryptor.decrypt(encrypted_message.chomp) # Decrypt the message here
|
52
|
+
uuid, message_content = extract_uuid(message)
|
53
|
+
@broker.broadcast(message_content)
|
54
54
|
end
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
55
|
+
rescue Errno::ECONNRESET
|
56
|
+
client.close
|
57
|
+
end
|
58
|
+
rescue StandardError => exception
|
59
|
+
#TODO we need to find the place for a global exception handler
|
59
60
|
end
|
60
61
|
end
|
61
62
|
end
|
@@ -71,9 +72,10 @@ module Kafkr
|
|
71
72
|
# Check if message is valid JSON
|
72
73
|
begin
|
73
74
|
message = JSON.parse(message)
|
75
|
+
Kafkr.log ">> #{message}"
|
74
76
|
return message["uuid"], message
|
75
77
|
rescue JSON::ParserError => e
|
76
|
-
|
78
|
+
Kafkr.log ">> #{message}"
|
77
79
|
match_data = /^(\w{8}-\w{4}-\w{4}-\w{4}-\w{12}): (.+)$/.match(message)
|
78
80
|
match_data ? [match_data[1], match_data[2]] : [nil, nil]
|
79
81
|
end
|
data/lib/kafkr/message_broker.rb
CHANGED
@@ -13,10 +13,7 @@ module Kafkr
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def broadcast(message)
|
16
|
-
Kafkr.
|
17
|
-
|
18
|
-
encrypted_message = Kafkr::Encryptor.new.encrypt(message)
|
19
|
-
|
16
|
+
encrypted_message = Kafkr::Encryptor.new.encrypt(message)
|
20
17
|
@subscribers.each do |subscriber|
|
21
18
|
if !subscriber.closed?
|
22
19
|
subscriber.puts(encrypted_message)
|
@@ -25,8 +22,13 @@ module Kafkr
|
|
25
22
|
rescue Errno::EPIPE
|
26
23
|
# Optionally, handle broken pipe error
|
27
24
|
rescue IOError
|
28
|
-
|
29
|
-
|
25
|
+
begin
|
26
|
+
@subscribers.delete(subscriber)
|
27
|
+
@last_sent.delete(subscriber)
|
28
|
+
rescue
|
29
|
+
puts "clean up subscribers"
|
30
|
+
end
|
31
|
+
|
30
32
|
end
|
31
33
|
end
|
32
34
|
end
|
data/lib/kafkr/producer.rb
CHANGED
data/lib/kafkr/version.rb
CHANGED
data/lib/kafkr.rb
CHANGED
@@ -75,16 +75,7 @@ module Kafkr
|
|
75
75
|
|
76
76
|
def write(message, unique_id = nil)
|
77
77
|
begin
|
78
|
-
|
79
|
-
rescue => e
|
80
|
-
unique_id = "unknown"
|
81
|
-
@logger.error("Failed to generate UUID: #{e.message}")
|
82
|
-
end
|
83
|
-
formatted_message = "[#{unique_id}] #{message}"
|
84
|
-
|
85
|
-
begin
|
86
|
-
puts formatted_message if development?
|
87
|
-
logger.info(formatted_message)
|
78
|
+
logger.info(message)
|
88
79
|
rescue IOError => e
|
89
80
|
@logger.error("Failed to write log: #{e.message}")
|
90
81
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kafkr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.18.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Delaney Kuldvee Burke
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-04-
|
11
|
+
date: 2024-04-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gibberish
|