sbmt-kafka_consumer 2.7.0 → 2.8.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 +12 -0
- data/lib/sbmt/kafka_consumer/base_consumer.rb +9 -12
- data/lib/sbmt/kafka_consumer/inbox_consumer.rb +14 -19
- data/lib/sbmt/kafka_consumer/testing/shared_contexts/with_sbmt_karafka_consumer.rb +3 -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: 5c5c4115c8a5cc26e7d4798244f8e3052f1b6abdddb11a4a96699a1e4f950659
|
4
|
+
data.tar.gz: 7e6d290f5d0866f4e6ea0b424e07afd95770840d6a5a1324ee4d01b28c62b49d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f07ac9ad6a9e65898e9d3a48ed86b0df7fdd52f38ea04b2e41aa0406351d314f0a5aa72e33334e9a619779564afb6105481d19ec2a27706adf197346af66776
|
7
|
+
data.tar.gz: 1d65a2e194afade6fc2230bd9d031c457101f799342ea688be292a119ae0661754f4cbca62ce66d8257af2616faef675bdc638ef03059a4eaa9611f41de8a674
|
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
|
+
## [2.8.0] - 2024-09-09
|
17
|
+
|
18
|
+
### Fixed
|
19
|
+
|
20
|
+
- Refactor consumer class initialization
|
21
|
+
|
22
|
+
## [2.7.1] - 2024-08-01
|
23
|
+
|
24
|
+
### Fixed
|
25
|
+
|
26
|
+
- Add mock `mark_as_consumed` for tests
|
27
|
+
|
16
28
|
## [2.7.0] - 2024-07-30
|
17
29
|
|
18
30
|
### Changed
|
@@ -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
|
@@ -112,14 +117,6 @@ module Sbmt
|
|
112
117
|
end
|
113
118
|
end
|
114
119
|
|
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
120
|
# can be overridden in consumer to enable message logging
|
124
121
|
def log_payload?
|
125
122
|
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
|
@@ -16,14 +16,14 @@ 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!
|
25
24
|
allow(kafka_client).to receive(:assignment_lost?).and_return(false)
|
26
25
|
allow(kafka_client).to receive(:mark_as_consumed!).and_return(true)
|
26
|
+
allow(kafka_client).to receive(:mark_as_consumed).and_return(true)
|
27
27
|
}
|
28
28
|
|
29
29
|
def publish_to_sbmt_karafka(raw_payload, opts = {})
|
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: 2.
|
4
|
+
version: 2.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sbermarket Ruby-Platform Team
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-09-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -570,7 +570,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
570
570
|
- !ruby/object:Gem::Version
|
571
571
|
version: '0'
|
572
572
|
requirements: []
|
573
|
-
rubygems_version: 3.
|
573
|
+
rubygems_version: 3.3.7
|
574
574
|
signing_key:
|
575
575
|
specification_version: 4
|
576
576
|
summary: Ruby gem for consuming Kafka messages
|