sbmt-kafka_consumer 2.7.1 → 2.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8d08a056092306a4834b63b1fe86534f25e949839469e13f38aade18974939c9
4
- data.tar.gz: cdf36647d564ac2d84fb06e4ca4e317d9e8dadb50a800a6f291de1a562ccc43a
3
+ metadata.gz: 5c5c4115c8a5cc26e7d4798244f8e3052f1b6abdddb11a4a96699a1e4f950659
4
+ data.tar.gz: 7e6d290f5d0866f4e6ea0b424e07afd95770840d6a5a1324ee4d01b28c62b49d
5
5
  SHA512:
6
- metadata.gz: 4877508c1f2c51e4ccbfb7dab086af8deb19c122039c93ee1e7552370e9c12f02765b9459b9c6119a7fa5d7766742913116896a67ad1423ae38f896026fad109
7
- data.tar.gz: c1664eff5a8a4a58f5f342f8aabfd825c74268d89999ea5924aede943b0c31eee952ef4012ef7c15b5810cc6d3d847218d59fbb11339db90110aebf53838d1e8
6
+ metadata.gz: 4f07ac9ad6a9e65898e9d3a48ed86b0df7fdd52f38ea04b2e41aa0406351d314f0a5aa72e33334e9a619779564afb6105481d19ec2a27706adf197346af66776
7
+ data.tar.gz: 1d65a2e194afade6fc2230bd9d031c457101f799342ea688be292a119ae0661754f4cbca62ce66d8257af2616faef675bdc638ef03059a4eaa9611f41de8a674
data/CHANGELOG.md CHANGED
@@ -13,6 +13,12 @@ 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
+
16
22
  ## [2.7.1] - 2024-08-01
17
23
 
18
24
  ### Fixed
@@ -3,15 +3,20 @@
3
3
  module Sbmt
4
4
  module KafkaConsumer
5
5
  class BaseConsumer < Karafka::BaseConsumer
6
- def self.consumer_klass(skip_on_error: false, middlewares: [])
7
- Class.new(self) do
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
- def self.consumer_klass(inbox_item:, event_name: nil, skip_on_error: false, name: nil, middlewares: [])
10
- Class.new(self) do
11
- const_set(:INBOX_ITEM_CLASS_NAME, inbox_item)
12
- const_set(:EVENT_NAME, event_name)
13
- const_set(:SKIP_ON_ERROR, skip_on_error)
14
- const_set(:MIDDLEWARES, middlewares.map(&:constantize))
15
-
16
- def self.name
17
- superclass.name
18
- end
19
- end
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,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(:consumer) {
20
- build_consumer(described_class.new)
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!
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Sbmt
4
4
  module KafkaConsumer
5
- VERSION = "2.7.1"
5
+ VERSION = "2.8.0"
6
6
  end
7
7
  end
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.7.1
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-08-01 00:00:00.000000000 Z
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.1.6
573
+ rubygems_version: 3.3.7
574
574
  signing_key:
575
575
  specification_version: 4
576
576
  summary: Ruby gem for consuming Kafka messages