deimos-ruby 2.0.12 → 2.0.14
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/CHANGELOG.md +8 -0
- data/lib/deimos/ext/producer_middleware.rb +2 -1
- data/lib/deimos/logging.rb +1 -1
- data/lib/deimos/test_helpers.rb +2 -0
- data/lib/deimos/version.rb +1 -1
- data/lib/deimos.rb +2 -0
- data/spec/producer_spec.rb +44 -0
- data/spec/spec_helper.rb +15 -0
- data/spec/utils/outbox_producer_spec.rb +11 -0
- 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: e8597163d34a0b2afd7ef60bbc2eda8f08c4e441292181dc7d15215ad4b2ebd7
|
4
|
+
data.tar.gz: 364899fa4738dd1df44f98cecc67bdc503f1a679a26274f78b49bd8b29c1ee02
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54eff5f5b0f375816b3a25516f602985b00440fe522d5495346fcb873d37fb1a822666ad04623c74002a15c15c3a70ba851099096d72eaba8ab9840a460ddbc2
|
7
|
+
data.tar.gz: 9901785951d244c09fc81ca6601c6700149b2f03f8246f167fe594fce778c035a1f81a1a468045930cf94e5787cecffcefdf069132cfe57686ec0172c8a28f5c
|
data/CHANGELOG.md
CHANGED
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
7
7
|
|
8
8
|
## UNRELEASED
|
9
9
|
|
10
|
+
## 2.0.14 - 2025-05-26
|
11
|
+
|
12
|
+
- Fix: Log actual payloads by default (was logging "null" for the payload).
|
13
|
+
|
14
|
+
## 2.0.13 - 2025-05-26
|
15
|
+
|
16
|
+
- Fix: Outbox producer would crash if no Deimos producer was defined for the topic.
|
17
|
+
|
10
18
|
## 2.0.12 - 2025-05-22
|
11
19
|
|
12
20
|
- Fix: Allow for hot reloading of producer classes without crashing.
|
@@ -9,9 +9,10 @@ module Deimos
|
|
9
9
|
producer: self,
|
10
10
|
message: message
|
11
11
|
) do
|
12
|
+
return message if message.delete(:already_encoded)
|
13
|
+
|
12
14
|
config = Deimos.karafka_config_for(topic: message[:topic])
|
13
15
|
return message if config.nil? || config.schema.nil?
|
14
|
-
return message if message.delete(:already_encoded)
|
15
16
|
return if message[:payload] && !message[:payload].is_a?(Hash) && !message[:payload].is_a?(SchemaClass::Record)
|
16
17
|
|
17
18
|
m = Deimos::Message.new(message[:payload].to_h,
|
data/lib/deimos/logging.rb
CHANGED
data/lib/deimos/test_helpers.rb
CHANGED
@@ -98,6 +98,8 @@ module Deimos
|
|
98
98
|
message_key = Deimos::TestHelpers.normalize_message(key)
|
99
99
|
hash_matcher = RSpec::Matchers::BuiltIn::Match.new(message)
|
100
100
|
Deimos::TestHelpers.sent_messages.any? do |m|
|
101
|
+
return m[:payload] == message if message.is_a?(String)
|
102
|
+
|
101
103
|
message.delete(:payload_key) if message.respond_to?(:[]) && message[:payload_key].nil?
|
102
104
|
m[:payload].delete(:payload_key) if m.respond_to?(:[]) && m[:payload]&.respond_to?(:[]) && m[:payload][:payload_key].nil?
|
103
105
|
hash_matcher.send(:match, message, m[:payload]) &&
|
data/lib/deimos/version.rb
CHANGED
data/lib/deimos.rb
CHANGED
@@ -107,6 +107,8 @@ module Deimos
|
|
107
107
|
topic = topic.sub(Deimos.config.producers.topic_prefix, '')
|
108
108
|
end
|
109
109
|
config = karafka_config_for(topic: topic)
|
110
|
+
return message unless config
|
111
|
+
|
110
112
|
message[:payload] = config.deserializers[:payload].decode_message_hash(message[:payload])
|
111
113
|
if message[:key] && config.deserializers[:key].respond_to?(:decode_message_hash)
|
112
114
|
message[:key] = config.deserializers[:key].decode_message_hash(message[:key])
|
data/spec/producer_spec.rb
CHANGED
@@ -272,6 +272,50 @@ module ProducerTest
|
|
272
272
|
}, '456', '4561')
|
273
273
|
end
|
274
274
|
|
275
|
+
describe 'payload logging' do
|
276
|
+
context 'with default / full' do
|
277
|
+
it 'should log full payload' do
|
278
|
+
allow(Karafka.logger).to receive(:info)
|
279
|
+
MyProducerWithID.publish_list(
|
280
|
+
[
|
281
|
+
{ 'test_id' => 'foo', 'some_int' => 123, :payload_key => 'key' },
|
282
|
+
{ 'test_id' => 'foo2', 'some_int' => 123, :payload_key => 'key2' },
|
283
|
+
]
|
284
|
+
)
|
285
|
+
expect(Karafka.logger).to have_received(:info).with(match_message({
|
286
|
+
'message' => 'Publishing Messages:',
|
287
|
+
'payloads' => [
|
288
|
+
{
|
289
|
+
'payload' => { 'test_id' => 'foo', 'some_int' => 123 },
|
290
|
+
'key' => 'key'
|
291
|
+
},
|
292
|
+
{
|
293
|
+
'payload' => { 'test_id' => 'foo2', 'some_int' => 123 },
|
294
|
+
'key' => 'key2'
|
295
|
+
}
|
296
|
+
]
|
297
|
+
}))
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
context 'with count' do
|
302
|
+
it 'should log only count' do
|
303
|
+
Deimos.karafka_config_for(topic: 'my-topic-with-id').payload_log :count
|
304
|
+
allow(Karafka.logger).to receive(:info)
|
305
|
+
MyProducerWithID.publish_list(
|
306
|
+
[
|
307
|
+
{ 'test_id' => 'foo', 'some_int' => 123, :payload_key => 'key' },
|
308
|
+
{ 'test_id' => 'foo2', 'some_int' => 123, :payload_key => 'key' }
|
309
|
+
]
|
310
|
+
)
|
311
|
+
expect(Karafka.logger).to have_received(:info).with(match_message({
|
312
|
+
'message' => 'Publishing Messages:',
|
313
|
+
'payloads_count' => 2
|
314
|
+
}))
|
315
|
+
end
|
316
|
+
end
|
317
|
+
end
|
318
|
+
|
275
319
|
context 'with Schema Class payloads' do
|
276
320
|
it 'should fail on invalid message with error handler' do
|
277
321
|
expect(Deimos::ProducerMiddleware).to receive(:call).and_raise('OH NOES')
|
data/spec/spec_helper.rb
CHANGED
@@ -343,3 +343,18 @@ RSpec.shared_context('with publish_backend') do
|
|
343
343
|
end
|
344
344
|
end
|
345
345
|
end
|
346
|
+
|
347
|
+
RSpec::Matchers.define :match_message do |msg|
|
348
|
+
match do |actual|
|
349
|
+
begin
|
350
|
+
parsed = JSON.parse(actual)
|
351
|
+
parsed['payloads']&.each do |p|
|
352
|
+
p['payload'].delete('timestamp')
|
353
|
+
p['payload'].delete('message_id')
|
354
|
+
end
|
355
|
+
expect(parsed).to match(a_hash_including(msg))
|
356
|
+
rescue JSON::ParserError
|
357
|
+
false
|
358
|
+
end
|
359
|
+
end
|
360
|
+
end
|
@@ -340,6 +340,17 @@ each_db_config(Deimos::Utils::OutboxProducer) do
|
|
340
340
|
end
|
341
341
|
|
342
342
|
example 'Full integration test' do
|
343
|
+
Deimos::KafkaMessage.create!(topic: "topic1",
|
344
|
+
message: "mess1",
|
345
|
+
partition_key: "key1")
|
346
|
+
producer.process_next_messages
|
347
|
+
expect(Deimos::KafkaTopicInfo.count).to eq(1)
|
348
|
+
expect(Deimos::KafkaTopicInfo.first.topic).to eq('topic1')
|
349
|
+
expect(Deimos::KafkaMessage.count).to eq(0)
|
350
|
+
expect('topic1').to have_sent('mess1')
|
351
|
+
end
|
352
|
+
|
353
|
+
example 'Integration test - batching' do
|
343
354
|
(1..4).each do |i|
|
344
355
|
(1..2).each do |j|
|
345
356
|
Deimos::KafkaMessage.create!(topic: "topic#{j}",
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deimos-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Orner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-05-
|
11
|
+
date: 2025-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: avro_turf
|