sbmt-kafka_consumer 3.0.0 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +18 -0
- data/lib/sbmt/kafka_consumer/base_consumer.rb +10 -15
- data/lib/sbmt/kafka_consumer/inbox_consumer.rb +14 -19
- data/lib/sbmt/kafka_consumer/instrumentation/logger_listener.rb +32 -6
- data/lib/sbmt/kafka_consumer/testing/shared_contexts/with_sbmt_karafka_consumer.rb +2 -3
- data/lib/sbmt/kafka_consumer/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 884f55960d86ac5b756f5b7defc30298e6918a543a168f69613972b6f4dd1282
|
4
|
+
data.tar.gz: 4521497f45d7c2bdf7fb78de36ddba7b077a51aee92c5c7aab41057e9b0e1f5a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d25efefade51458b46dd3f060983143f9de35d71d7e007dd082daf5f4a6d8a8a635daff400337d38a8621cdda1ad694e115f4816594cb9f94bd408ec8ddd2b9a
|
7
|
+
data.tar.gz: 7fcf377249867d6694515bf006af17de6ade409ddf813bffc63471d437cd1752f659c72d210f071fcf937f6be99f75bf4028e25a3b803d7abfd04e8fd464fdb3
|
data/CHANGELOG.md
CHANGED
@@ -13,6 +13,18 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|
13
13
|
|
14
14
|
### Fixed
|
15
15
|
|
16
|
+
## [3.2.0] - 2024-09-17
|
17
|
+
|
18
|
+
### Added
|
19
|
+
|
20
|
+
- For synchronous messages and errors, we place logs in tags
|
21
|
+
|
22
|
+
## [3.1.0] - 2024-09-09
|
23
|
+
|
24
|
+
### Fixed
|
25
|
+
|
26
|
+
- Refactor consumer class initialization
|
27
|
+
|
16
28
|
## [3.0.0] - 2024-09-04
|
17
29
|
|
18
30
|
## BREAKING
|
@@ -25,6 +37,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|
25
37
|
|
26
38
|
- Support consumer group mappers to support backward compatibility of consumer group naming
|
27
39
|
|
40
|
+
## [2.8.0] - 2024-09-09
|
41
|
+
|
42
|
+
### Fixed
|
43
|
+
|
44
|
+
- Refactor consumer class initialization
|
45
|
+
|
28
46
|
## [2.7.1] - 2024-08-01
|
29
47
|
|
30
48
|
### Fixed
|
@@ -3,15 +3,20 @@
|
|
3
3
|
module Sbmt
|
4
4
|
module KafkaConsumer
|
5
5
|
class BaseConsumer < Karafka::BaseConsumer
|
6
|
-
|
7
|
-
|
8
|
-
const_set(:SKIP_ON_ERROR, skip_on_error)
|
9
|
-
const_set(:MIDDLEWARES, middlewares.map(&:constantize))
|
6
|
+
class_attribute :skip_on_error, instance_writer: false, default: false
|
7
|
+
class_attribute :middlewares, instance_writer: false, default: []
|
10
8
|
|
9
|
+
def self.consumer_klass(skip_on_error: nil, middlewares: nil)
|
10
|
+
klass = Class.new(self) do
|
11
11
|
def self.name
|
12
12
|
superclass.name
|
13
13
|
end
|
14
14
|
end
|
15
|
+
|
16
|
+
# defaults are set in class_attribute definition
|
17
|
+
klass.skip_on_error = skip_on_error if skip_on_error
|
18
|
+
klass.middlewares = middlewares.map(&:constantize) if middlewares
|
19
|
+
klass
|
15
20
|
end
|
16
21
|
|
17
22
|
def consume
|
@@ -40,9 +45,7 @@ module Sbmt
|
|
40
45
|
|
41
46
|
def with_instrumentation(message)
|
42
47
|
logger.tagged(
|
43
|
-
trace_id: trace_id
|
44
|
-
topic: message.metadata.topic, partition: message.metadata.partition,
|
45
|
-
key: message.metadata.key, offset: message.metadata.offset
|
48
|
+
trace_id: trace_id
|
46
49
|
) do
|
47
50
|
::Sbmt::KafkaConsumer.monitor.instrument(
|
48
51
|
"consumer.consumed_one",
|
@@ -112,14 +115,6 @@ module Sbmt
|
|
112
115
|
end
|
113
116
|
end
|
114
117
|
|
115
|
-
def skip_on_error
|
116
|
-
self.class::SKIP_ON_ERROR
|
117
|
-
end
|
118
|
-
|
119
|
-
def middlewares
|
120
|
-
self.class::MIDDLEWARES
|
121
|
-
end
|
122
|
-
|
123
118
|
# can be overridden in consumer to enable message logging
|
124
119
|
def log_payload?
|
125
120
|
false
|
@@ -6,17 +6,20 @@ module Sbmt
|
|
6
6
|
IDEMPOTENCY_HEADER_NAME = "Idempotency-Key"
|
7
7
|
DEFAULT_SOURCE = "KAFKA"
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
9
|
+
class_attribute :inbox_item_class, instance_writer: false, default: nil
|
10
|
+
class_attribute :event_name, instance_writer: false, default: nil
|
11
|
+
|
12
|
+
def self.consumer_klass(inbox_item:, event_name: nil, skip_on_error: nil, name: nil, middlewares: nil)
|
13
|
+
# defaults are set in class_attribute definition
|
14
|
+
klass = super(skip_on_error: skip_on_error, middlewares: middlewares)
|
15
|
+
klass.inbox_item_class = inbox_item.constantize
|
16
|
+
klass.event_name = event_name if event_name
|
17
|
+
klass
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize
|
21
|
+
raise Sbmt::KafkaConsumer::Error, "inbox_item param is not set" if inbox_item_class.blank?
|
22
|
+
super
|
20
23
|
end
|
21
24
|
|
22
25
|
def extra_message_attrs(_message)
|
@@ -101,14 +104,6 @@ module Sbmt
|
|
101
104
|
message.metadata.headers.fetch(IDEMPOTENCY_HEADER_NAME, nil).presence
|
102
105
|
end
|
103
106
|
|
104
|
-
def inbox_item_class
|
105
|
-
@inbox_item_class ||= self.class::INBOX_ITEM_CLASS_NAME.constantize
|
106
|
-
end
|
107
|
-
|
108
|
-
def event_name
|
109
|
-
@event_name ||= self.class::EVENT_NAME
|
110
|
-
end
|
111
|
-
|
112
107
|
def inbox_name
|
113
108
|
inbox_item_class.box_name
|
114
109
|
end
|
@@ -20,30 +20,56 @@ module Sbmt
|
|
20
20
|
|
21
21
|
logger.tagged(
|
22
22
|
type: type,
|
23
|
+
stacktrace: log_backtrace(error),
|
23
24
|
**tags
|
24
25
|
) do
|
25
26
|
logger.error(error_message(error))
|
26
|
-
log_backtrace(error)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
30
|
# BaseConsumer events
|
31
31
|
def on_consumer_consumed_one(event)
|
32
|
-
|
32
|
+
log_with_tags(log_tags(event), "Successfully consumed message")
|
33
33
|
end
|
34
34
|
|
35
35
|
def on_consumer_mark_as_consumed(event)
|
36
|
-
|
36
|
+
log_with_tags(log_tags(event), "Processing message")
|
37
37
|
end
|
38
38
|
|
39
39
|
def on_consumer_process_message(event)
|
40
|
-
|
40
|
+
log_with_tags(log_tags(event), "Commit offset")
|
41
41
|
end
|
42
42
|
|
43
43
|
# InboxConsumer events
|
44
44
|
def on_consumer_inbox_consumed_one(event)
|
45
|
-
|
46
|
-
|
45
|
+
log_tags = log_tags(event).merge!(status: event[:status])
|
46
|
+
msg = "Successfully consumed message with uuid: #{event[:message_uuid]}"
|
47
|
+
|
48
|
+
log_with_tags(log_tags, msg)
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def log_tags(event)
|
54
|
+
metadata = event.payload[:message].metadata
|
55
|
+
|
56
|
+
{
|
57
|
+
kafka: {
|
58
|
+
topic: metadata.topic,
|
59
|
+
partition: metadata.partition,
|
60
|
+
key: metadata.key,
|
61
|
+
offset: metadata.offset,
|
62
|
+
consumer_group: event.payload[:caller].topic.consumer_group.id,
|
63
|
+
consume_duration_ms: event.payload[:time]
|
64
|
+
}
|
65
|
+
}
|
66
|
+
end
|
67
|
+
|
68
|
+
def log_with_tags(log_tags, msg)
|
69
|
+
return unless logger.respond_to?(:tagged)
|
70
|
+
|
71
|
+
logger.tagged(log_tags) do
|
72
|
+
logger.send(:info, msg)
|
47
73
|
end
|
48
74
|
end
|
49
75
|
end
|
@@ -16,9 +16,8 @@ RSpec.shared_context "with sbmt karafka consumer" do
|
|
16
16
|
let(:kafka_client) { instance_double(Karafka::Connection::Client) }
|
17
17
|
let(:null_deserializer) { Sbmt::KafkaConsumer::Serialization::NullDeserializer.new }
|
18
18
|
|
19
|
-
let(:
|
20
|
-
|
21
|
-
}
|
19
|
+
let(:consumer_class) { described_class.consumer_klass }
|
20
|
+
let(:consumer) { build_consumer(consumer_class.new) }
|
22
21
|
|
23
22
|
before {
|
24
23
|
Sbmt::KafkaConsumer::ClientConfigurer.configure!
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sbmt-kafka_consumer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kuper Ruby-Platform Team
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-09-
|
11
|
+
date: 2024-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -565,7 +565,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
565
565
|
- !ruby/object:Gem::Version
|
566
566
|
version: '0'
|
567
567
|
requirements: []
|
568
|
-
rubygems_version: 3.
|
568
|
+
rubygems_version: 3.1.6
|
569
569
|
signing_key:
|
570
570
|
specification_version: 4
|
571
571
|
summary: Ruby gem for consuming Kafka messages
|