kafkr 0.5.7 → 0.10.0
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 +4 -4
- data/.DS_Store +0 -0
- data/exe/kafkr +3 -1
- data/exe/kafkr-consumer +3 -3
- data/exe/kafkr-producer +1 -1
- data/lib/kafkr/consumer.rb +28 -85
- data/lib/kafkr/encryptor.rb +1 -1
- data/lib/kafkr/log.rb +17 -53
- data/lib/kafkr/producer.rb +21 -91
- data/lib/kafkr/version.rb +1 -1
- data/lib/kafkr.rb +1 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a404654568d9f0c4a16e16f2341757b231cefd27e02186a4de5e34e945afe07
|
4
|
+
data.tar.gz: 3acf9756a6d8ff3f372d595171cb967736430768c6181b7aca9e79f44061bc8f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b7ca82215482129450e112709ed46533be1638d525b433d92d571b188f93d01c787be4a4eb31cad4509d7c96df23850795bf77171972178491c2ed850868a2e0
|
7
|
+
data.tar.gz: 7bb54ca0f2ac1fdd3a4db32c12f8e90bc70dfd272007b9b17204a177d488788f5c3c4430a2f12920e07c614f92deac0cd8d3b4a007ee4fc12253dea4b0efe447
|
data/.DS_Store
ADDED
Binary file
|
data/exe/kafkr
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
require_relative "../lib/kafkr.rb"
|
3
|
+
|
2
4
|
PORT = ENV["KAFKR_PORT"] || 4000
|
3
5
|
|
4
6
|
begin
|
@@ -10,7 +12,7 @@ end
|
|
10
12
|
|
11
13
|
begin
|
12
14
|
server = Kafkr::Log.new(PORT.to_i)
|
13
|
-
puts "Log started on port #{PORT}!"
|
15
|
+
puts "Kafkr Log version #{Kafkr::VERSION} started on port #{PORT}!"
|
14
16
|
server.start
|
15
17
|
rescue => e
|
16
18
|
puts "An error occurred: #{e.message}"
|
data/exe/kafkr-consumer
CHANGED
@@ -33,7 +33,7 @@ def list_registered_handlers
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
def start_consumer(port,host)
|
36
|
+
def start_consumer(port, host)
|
37
37
|
puts "Starting consumer on port #{port}!"
|
38
38
|
$handlers_changed = false
|
39
39
|
|
@@ -95,13 +95,13 @@ end
|
|
95
95
|
|
96
96
|
file_checksums = {}
|
97
97
|
monitoring_thread = Thread.new { monitor_handlers(file_checksums) }
|
98
|
-
start_consumer(port,host) # Pass the port here
|
98
|
+
start_consumer(port, host) # Pass the port here
|
99
99
|
|
100
100
|
begin
|
101
101
|
loop do
|
102
102
|
if $restart_required
|
103
103
|
stop_consumer
|
104
|
-
start_consumer(port,host)
|
104
|
+
start_consumer(port, host)
|
105
105
|
$restart_required = false
|
106
106
|
end
|
107
107
|
sleep 1
|
data/exe/kafkr-producer
CHANGED
data/lib/kafkr/consumer.rb
CHANGED
@@ -18,6 +18,7 @@ module Kafkr
|
|
18
18
|
def configuration
|
19
19
|
FileUtils.mkdir_p "./.kafkr"
|
20
20
|
@configuration ||= OpenStruct.new
|
21
|
+
@configuration.suggest_handlers = false
|
21
22
|
@configuration
|
22
23
|
end
|
23
24
|
|
@@ -38,7 +39,6 @@ module Kafkr
|
|
38
39
|
end
|
39
40
|
|
40
41
|
def load_handlers(directory = "./handlers")
|
41
|
-
# Load handlers and check for new additions
|
42
42
|
Dir.glob("#{directory}/*.rb").each do |file|
|
43
43
|
handler_name = File.basename(file, ".rb")
|
44
44
|
unless $loaded_handlers[handler_name]
|
@@ -47,11 +47,6 @@ module Kafkr
|
|
47
47
|
$handlers_changed = true
|
48
48
|
end
|
49
49
|
end
|
50
|
-
|
51
|
-
# Display handlers if there are changes
|
52
|
-
if $handlers_changed
|
53
|
-
$handlers_changed = false
|
54
|
-
end
|
55
50
|
end
|
56
51
|
end
|
57
52
|
|
@@ -64,21 +59,19 @@ module Kafkr
|
|
64
59
|
raise NotImplementedError, "You must implement the handle method"
|
65
60
|
end
|
66
61
|
|
67
|
-
# ... rest of your existing Handler methods ...
|
68
62
|
def self.inherited(subclass)
|
69
63
|
Consumer.register_handler(subclass.new)
|
70
64
|
end
|
71
65
|
|
72
66
|
protected
|
73
67
|
|
74
|
-
def reply
|
75
|
-
|
68
|
+
def reply(to:, payload:)
|
76
69
|
Kafkr::Producer.configure do |config|
|
77
70
|
config.host = Consumer.configuration.host
|
78
71
|
config.port = Consumer.configuration.port
|
79
72
|
end
|
80
73
|
|
81
|
-
Kafkr::Producer.send_message({reply: {payload: payload, uuid: to[
|
74
|
+
Kafkr::Producer.send_message({reply: {payload: payload, uuid: to["sync_uid"]}})
|
82
75
|
end
|
83
76
|
|
84
77
|
private
|
@@ -114,47 +107,38 @@ module Kafkr
|
|
114
107
|
end
|
115
108
|
|
116
109
|
def valid_class_name?(name)
|
117
|
-
# A valid class name starts with an uppercase letter and
|
118
|
-
# followed by zero or more letters, numbers, or underscores.
|
119
110
|
/^[A-Z]\w*$/.match?(name)
|
120
111
|
end
|
121
112
|
|
122
|
-
# sugests a working handler
|
123
113
|
def print_handler_class(name)
|
124
114
|
return if name.is_a?(Numeric)
|
125
|
-
|
126
|
-
# If name is a Hash, use its first key
|
127
115
|
name = name.keys.first if name.is_a?(Hash)
|
128
|
-
|
129
|
-
# Generate the handler name based on the naming convention
|
130
116
|
handler_name = "#{name.downcase}_handler"
|
131
117
|
|
132
|
-
# Check if the handler is already loaded
|
133
118
|
if $loaded_handlers.key?(handler_name)
|
134
119
|
return
|
135
120
|
end
|
136
121
|
|
137
|
-
if
|
138
|
-
|
139
|
-
|
122
|
+
if Kafkr::Consumer.configuration.suggest_handlers
|
123
|
+
if valid_class_name?(name.capitalize)
|
124
|
+
puts "No handler for this message, you could use this one.\n\n"
|
140
125
|
|
141
|
-
|
126
|
+
handler_class_string = <<~HANDLER_CLASS
|
127
|
+
class #{name.capitalize}Handler < Kafkr::Consumer::Handler
|
128
|
+
def handle?(message)
|
129
|
+
can_handle? message, '#{name}'
|
130
|
+
end
|
142
131
|
|
143
|
-
|
144
|
-
|
145
|
-
|
132
|
+
def handle(message)
|
133
|
+
puts message
|
134
|
+
end
|
146
135
|
end
|
147
|
-
|
148
|
-
def handle(message)
|
149
|
-
puts message
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
save the file to ./handlers/#{name}_handler.rb
|
154
136
|
|
155
|
-
|
137
|
+
# Save the file to ./handlers/#{name}_handler.rb
|
138
|
+
HANDLER_CLASS
|
156
139
|
|
157
|
-
|
140
|
+
puts handler_class_string
|
141
|
+
end
|
158
142
|
end
|
159
143
|
end
|
160
144
|
|
@@ -163,38 +147,28 @@ module Kafkr
|
|
163
147
|
def listen_for(message, send_message)
|
164
148
|
attempt = 0
|
165
149
|
begin
|
166
|
-
socket = TCPSocket.new(
|
150
|
+
socket = TCPSocket.new(@host, @port)
|
167
151
|
attempt = 0
|
168
152
|
|
169
153
|
Timeout.timeout(20) do
|
170
|
-
|
171
|
-
sync_uid = send_message.call(message, acknowledge: false)
|
154
|
+
sync_uid = send_message.call(message)
|
172
155
|
|
173
156
|
loop do
|
174
157
|
received_message = socket.gets
|
175
158
|
raise LostConnection if received_message.nil?
|
176
|
-
|
177
|
-
received_message = Kafkr::Encryptor.new.decrypt(received_message.chomp)
|
178
|
-
# Yield every received message to the given block
|
159
|
+
received_message = Kafkr::Encryptor.new.decrypt(received_message.chomp)
|
179
160
|
if valid_json?(received_message)
|
180
|
-
|
181
|
-
|
161
|
+
payload = yield JSON.parse(received_message), sync_uid if block_given?
|
162
|
+
return payload if payload
|
182
163
|
end
|
183
164
|
end
|
184
165
|
end
|
185
|
-
rescue Timeout::Error
|
186
|
-
puts "Listening timed out after 20 seconds."
|
187
|
-
socket&.close
|
188
|
-
rescue LostConnection
|
166
|
+
rescue Timeout::Error, LostConnection, Errno::ECONNREFUSED
|
189
167
|
attempt += 1
|
190
168
|
wait_time = backoff_time(attempt)
|
191
|
-
puts "
|
192
|
-
sleep(wait_time)
|
193
|
-
rescue Errno::ECONNREFUSED, Timeout::Error
|
194
|
-
attempt += 1
|
195
|
-
wait_time = backoff_time(attempt)
|
196
|
-
puts "Failed to connect on attempt #{attempt}. Retrying in #{wait_time} seconds..."
|
169
|
+
puts "Attempt #{attempt}: Retrying in #{wait_time} seconds..."
|
197
170
|
sleep(wait_time)
|
171
|
+
retry
|
198
172
|
rescue Interrupt
|
199
173
|
puts "Received interrupt signal. Shutting down consumer gracefully..."
|
200
174
|
socket&.close
|
@@ -205,39 +179,9 @@ module Kafkr
|
|
205
179
|
def listen
|
206
180
|
attempt = 0
|
207
181
|
loop do
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
loop do
|
212
|
-
message = socket.gets
|
213
|
-
raise LostConnection if message.nil?
|
214
|
-
|
215
|
-
# Assuming Kafkr::Encryptor is defined elsewhere
|
216
|
-
message = Kafkr::Encryptor.new.decrypt(message.chomp)
|
217
|
-
if valid_json?(message)
|
218
|
-
dispatch_to_handlers(JSON.parse(message)) do |message|
|
219
|
-
yield message if block_given?
|
220
|
-
end
|
221
|
-
else
|
222
|
-
dispatch_to_handlers(message) do |message|
|
223
|
-
yield message if block_given?
|
224
|
-
end
|
225
|
-
end
|
182
|
+
listen_for("dummy", ->(msg) { puts "Listening..." }) do |message|
|
183
|
+
puts "Received message: #{message}"
|
226
184
|
end
|
227
|
-
rescue LostConnection
|
228
|
-
attempt += 1
|
229
|
-
wait_time = backoff_time(attempt)
|
230
|
-
puts "Connection lost. Reconnecting in #{wait_time} seconds..."
|
231
|
-
sleep(wait_time)
|
232
|
-
rescue Errno::ECONNREFUSED, Timeout::Error
|
233
|
-
attempt += 1
|
234
|
-
wait_time = backoff_time(attempt)
|
235
|
-
puts "Failed to connect on attempt #{attempt}. Retrying in #{wait_time} seconds..."
|
236
|
-
sleep(wait_time)
|
237
|
-
rescue Interrupt
|
238
|
-
puts "Received interrupt signal. Shutting down consumer gracefully..."
|
239
|
-
socket&.close
|
240
|
-
exit(0)
|
241
185
|
end
|
242
186
|
end
|
243
187
|
|
@@ -271,6 +215,5 @@ module Kafkr
|
|
271
215
|
end
|
272
216
|
end
|
273
217
|
|
274
|
-
# Assuming the handlers directory is the default location
|
275
218
|
Consumer.load_handlers
|
276
219
|
end
|
data/lib/kafkr/encryptor.rb
CHANGED
data/lib/kafkr/log.rb
CHANGED
@@ -8,22 +8,17 @@ module Kafkr
|
|
8
8
|
@received_file = "./.kafkr/log.txt"
|
9
9
|
@broker = MessageBroker.new
|
10
10
|
@whitelist = load_whitelist
|
11
|
-
@acknowledged_message_ids = load_acknowledged_message_ids
|
12
11
|
end
|
13
12
|
|
14
|
-
def
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
def load_whitelist
|
14
|
+
whitelist = ["localhost", "::1", "127.0.0.1"]
|
15
|
+
if File.exist?("whitelist.txt")
|
16
|
+
File.readlines("whitelist.txt").each do |line|
|
17
|
+
ip = line.strip.sub(/^::ffff:/, "")
|
18
|
+
whitelist << ip
|
19
|
+
end
|
18
20
|
end
|
19
|
-
|
20
|
-
config_path = File.expand_path("./.kafkr/acknowledged_message_ids.txt")
|
21
|
-
return [] unless File.exist?(config_path)
|
22
|
-
|
23
|
-
File.readlines(config_path).map(&:strip)
|
24
|
-
rescue Errno::ENOENT, Errno::EACCES => e
|
25
|
-
puts "Error loading acknowledged_message_ids: #{e.message}"
|
26
|
-
[]
|
21
|
+
whitelist
|
27
22
|
end
|
28
23
|
|
29
24
|
def start
|
@@ -53,14 +48,7 @@ module Kafkr
|
|
53
48
|
message = decryptor.decrypt(encrypted_message.chomp) # Decrypt the message here
|
54
49
|
uuid, message_content = extract_uuid(message)
|
55
50
|
if uuid && message_content
|
56
|
-
|
57
|
-
acknowledge_existing_message(uuid, client)
|
58
|
-
else
|
59
|
-
acknowledge_message(uuid, client)
|
60
|
-
persist_received_message(uuid)
|
61
|
-
@acknowledged_message_ids << uuid
|
62
|
-
@broker.broadcast(message_content)
|
63
|
-
end
|
51
|
+
@broker.broadcast(message_content)
|
64
52
|
else
|
65
53
|
puts "Received invalid message format: #{message}"
|
66
54
|
end
|
@@ -73,17 +61,6 @@ module Kafkr
|
|
73
61
|
end
|
74
62
|
end
|
75
63
|
|
76
|
-
def load_whitelist
|
77
|
-
whitelist = ["localhost", "::1","127.0.0.1"]
|
78
|
-
if File.exist?("whitelist.txt")
|
79
|
-
File.readlines("whitelist.txt").each do |line|
|
80
|
-
ip = line.strip.sub(/^::ffff:/, "")
|
81
|
-
whitelist << ip
|
82
|
-
end
|
83
|
-
end
|
84
|
-
whitelist
|
85
|
-
end
|
86
|
-
|
87
64
|
def whitelisted?(ip)
|
88
65
|
@whitelist.include?(ip.gsub("::ffff:", ""))
|
89
66
|
end
|
@@ -91,27 +68,14 @@ module Kafkr
|
|
91
68
|
private
|
92
69
|
|
93
70
|
def extract_uuid(message)
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
puts "Acknowledgment sent to producer: #{acknowledgment_message}"
|
103
|
-
end
|
104
|
-
|
105
|
-
def acknowledge_existing_message(uuid, client)
|
106
|
-
puts "Received duplicate message with UUID #{uuid}. Already Acknowledged."
|
107
|
-
acknowledgment_message = "ACK-DUPLICATE: #{uuid}"
|
108
|
-
client.puts(acknowledgment_message)
|
109
|
-
puts "Duplicate acknowledgment sent to producer: #{acknowledgment_message}"
|
110
|
-
end
|
111
|
-
|
112
|
-
def persist_received_message(uuid)
|
113
|
-
File.open("./.kafkr/acknowledged_message_ids.txt", "a") do |file|
|
114
|
-
file.puts(uuid)
|
71
|
+
# Check if message is valid JSON
|
72
|
+
begin
|
73
|
+
message = JSON.parse(message)
|
74
|
+
return message["uuid"], message
|
75
|
+
rescue JSON::ParserError => e
|
76
|
+
puts "Received invalid message format: #{message}"
|
77
|
+
match_data = /^(\w{8}-\w{4}-\w{4}-\w{4}-\w{12}): (.+)$/.match(message)
|
78
|
+
match_data ? [match_data[1], match_data[2]] : [nil, nil]
|
115
79
|
end
|
116
80
|
end
|
117
81
|
end
|
data/lib/kafkr/producer.rb
CHANGED
@@ -10,17 +10,14 @@ module Kafkr
|
|
10
10
|
@@file_mutex = Mutex.new
|
11
11
|
|
12
12
|
MESSAGE_QUEUE = "./.kafkr/message_queue.txt"
|
13
|
-
ACKNOWLEDGED_MESSAGE_QUEUE = "./.kafkr/acknowledged_messages.txt"
|
14
13
|
|
15
14
|
def self.configuration
|
16
15
|
FileUtils.mkdir_p "./.kafkr"
|
17
16
|
@configuration ||= OpenStruct.new
|
18
17
|
@configuration.queue_file = MESSAGE_QUEUE
|
19
|
-
@configuration.acknowledged_file = ACKNOWLEDGED_MESSAGE_QUEUE
|
20
18
|
@configuration.message_queue = []
|
21
|
-
@configuration.acknowledged_messages = []
|
22
|
-
@configuration.acknowledged_messages = load_acknowledged_messages
|
23
19
|
load_queue_from_file
|
20
|
+
@configuration.is_json = false
|
24
21
|
@configuration
|
25
22
|
end
|
26
23
|
|
@@ -31,79 +28,54 @@ module Kafkr
|
|
31
28
|
end
|
32
29
|
|
33
30
|
def self.structured_data_to_hash(input:, sync_uid:)
|
34
|
-
# Check the overall structure with regex and make quotes optional
|
35
31
|
unless /\A\w+\s*(=>|<=>)\s*((\w+:\s*['"]?[^'",]*['"]?,\s*)*(\w+:\s*['"]?[^'",]*['"]?)\s*)\z/.match?(input)
|
36
32
|
return input
|
37
33
|
end
|
38
34
|
|
39
35
|
if input.include?("<=>")
|
40
|
-
# puts "sync message"
|
41
|
-
# Extract the type and key-value pairs
|
42
36
|
type, key_values_str = input.split("<=>").map(&:strip)
|
43
|
-
|
44
|
-
# puts type
|
45
|
-
# puts key_values_str
|
46
|
-
|
47
37
|
key_values = key_values_str.scan(/(\w+):\s*['"]?([^'",]*)['"]?/)
|
48
|
-
|
49
|
-
# Convert the array of pairs into a hash, stripping quotes if they exist
|
50
38
|
hash_body = key_values.to_h do |key, value|
|
51
39
|
[key.to_sym, value.strip.gsub(/\A['"]|['"]\z/, "")]
|
52
40
|
end
|
53
|
-
|
54
|
-
# Return the final hash with the type as the key
|
55
41
|
{type.to_sym => hash_body, :sync => true, :sync_uid => sync_uid}
|
56
|
-
|
57
42
|
else
|
58
|
-
# puts "async message"
|
59
|
-
# Extract the type and key-value pairs
|
60
43
|
type, key_values_str = input.split("=>").map(&:strip)
|
61
44
|
key_values = key_values_str.scan(/(\w+):\s*['"]?([^'",]*)['"]?/)
|
62
|
-
|
63
|
-
# Convert the array of pairs into a hash, stripping quotes if they exist
|
64
45
|
hash_body = key_values.to_h do |key, value|
|
65
46
|
[key.to_sym, value.strip.gsub(/\A['"]|['"]\z/, "")]
|
66
47
|
end
|
67
|
-
|
68
|
-
# Return the final hash with the type as the key
|
69
48
|
{type.to_sym => hash_body}
|
70
49
|
end
|
71
50
|
end
|
72
51
|
|
73
|
-
def self.send_message(message
|
52
|
+
def self.send_message(message)
|
74
53
|
uuid = SecureRandom.uuid
|
54
|
+
message_with_uuid = nil
|
75
55
|
|
76
|
-
if
|
77
|
-
|
78
|
-
|
79
|
-
|
56
|
+
if Kafkr::Producer.configuration.is_json
|
57
|
+
json_message = JSON.parse(message)
|
58
|
+
json_message["uuid"] = uuid
|
59
|
+
message_with_uuid = JSON.dump(json_message)
|
60
|
+
else
|
61
|
+
if message.is_a? String
|
62
|
+
message = structured_data_to_hash(input: message, sync_uid: uuid)
|
63
|
+
message_with_uuid = "#{uuid}: #{message}"
|
64
|
+
end
|
80
65
|
|
81
|
-
|
82
|
-
|
66
|
+
if message.is_a?(Hash)
|
67
|
+
message_with_uuid = "#{uuid}: #{JSON.generate(message)}"
|
68
|
+
end
|
83
69
|
end
|
84
70
|
|
85
|
-
# Encrypt the message here
|
86
71
|
encrypted_message_with_uuid = Kafkr::Encryptor.new.encrypt(message_with_uuid)
|
87
72
|
|
88
73
|
begin
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
listen_for_acknowledgments(socket) if acknowledge
|
93
|
-
send_queued_messages(socket)
|
94
|
-
# Send the encrypted message instead of the plain one
|
95
|
-
socket.puts(encrypted_message_with_uuid)
|
96
|
-
else
|
97
|
-
puts "Message with UUID #{uuid} has already been acknowledged. Skipping."
|
98
|
-
end
|
99
|
-
else
|
100
|
-
socket = TCPSocket.new(@configuration.host, @configuration.port)
|
101
|
-
send_queued_messages(socket)
|
102
|
-
socket.puts(encrypted_message_with_uuid)
|
103
|
-
end
|
74
|
+
socket = TCPSocket.new(@configuration.host, @configuration.port)
|
75
|
+
send_queued_messages(socket)
|
76
|
+
socket.puts(encrypted_message_with_uuid)
|
104
77
|
rescue Errno::ECONNREFUSED
|
105
78
|
puts "Connection refused. Queuing message: #{encrypted_message_with_uuid}"
|
106
|
-
# Queue the encrypted message
|
107
79
|
@configuration.message_queue.push(encrypted_message_with_uuid)
|
108
80
|
save_queue_to_file
|
109
81
|
rescue Errno::EPIPE
|
@@ -115,39 +87,15 @@ module Kafkr
|
|
115
87
|
end
|
116
88
|
|
117
89
|
def self.send_message_and_wait(message)
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
if received_message.key? "reply"
|
122
|
-
if received_message["reply"].dig('uuid') == sync_uid
|
123
|
-
received_message["reply"].dig('payload')
|
124
|
-
end
|
90
|
+
Consumer.new.listen_for(message, method(:send_message)) do |received_message, sync_uid|
|
91
|
+
if received_message.key? "reply" and received_message["reply"].dig("uuid") == sync_uid
|
92
|
+
received_message["reply"].dig("payload")
|
125
93
|
end
|
126
|
-
|
127
94
|
end
|
128
|
-
|
129
|
-
payload
|
130
95
|
end
|
131
96
|
|
132
97
|
private
|
133
98
|
|
134
|
-
def self.listen_for_acknowledgments(socket)
|
135
|
-
Thread.new do
|
136
|
-
while line = socket.gets
|
137
|
-
line = line.chomp
|
138
|
-
if line.start_with?("ACK:")
|
139
|
-
uuid = line.split(" ")[1]
|
140
|
-
handle_acknowledgment(uuid)
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
def self.handle_acknowledgment(uuid)
|
147
|
-
@configuration.acknowledged_messages << uuid
|
148
|
-
save_acknowledged_messages
|
149
|
-
end
|
150
|
-
|
151
99
|
def self.retry_connection(message_with_uuid)
|
152
100
|
sleep(5)
|
153
101
|
send_message(message_with_uuid)
|
@@ -176,24 +124,6 @@ module Kafkr
|
|
176
124
|
end
|
177
125
|
end
|
178
126
|
|
179
|
-
def self.load_acknowledged_messages
|
180
|
-
@@file_mutex.synchronize do
|
181
|
-
if File.exist?(@configuration.acknowledged_file)
|
182
|
-
File.readlines(@configuration.acknowledged_file).map(&:chomp)
|
183
|
-
else
|
184
|
-
[]
|
185
|
-
end
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
def self.save_acknowledged_messages
|
190
|
-
@@file_mutex.synchronize do
|
191
|
-
File.open(@configuration.acknowledged_file, "w") do |file|
|
192
|
-
file.puts(@configuration.acknowledged_messages)
|
193
|
-
end
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
127
|
def self.logger
|
198
128
|
@logger ||= Logger.new(STDOUT)
|
199
129
|
end
|
data/lib/kafkr/version.rb
CHANGED
data/lib/kafkr.rb
CHANGED
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.10.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-
|
11
|
+
date: 2024-04-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gibberish
|
@@ -35,6 +35,7 @@ executables:
|
|
35
35
|
extensions: []
|
36
36
|
extra_rdoc_files: []
|
37
37
|
files:
|
38
|
+
- ".DS_Store"
|
38
39
|
- ".rspec"
|
39
40
|
- ".standard.yml"
|
40
41
|
- README.md
|
@@ -71,7 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
71
72
|
- !ruby/object:Gem::Version
|
72
73
|
version: '0'
|
73
74
|
requirements: []
|
74
|
-
rubygems_version: 3.5.
|
75
|
+
rubygems_version: 3.5.5
|
75
76
|
signing_key:
|
76
77
|
specification_version: 4
|
77
78
|
summary: A homage to kafkr implmented in ruby
|