sbmt-kafka_consumer 3.0.0 → 3.1.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: 7af7925acd4a61d131a66dd3cd290064ba11aac749ee64ca00841912bd038adc
4
- data.tar.gz: 9cd1e1f789c6e4252adedf3dd3115f512c62240b75edadc38d1590e4a85b6000
3
+ metadata.gz: f56ef789be2f19f5e5890292e8163f29d65ced1de23358b3a0bcf4163b77587d
4
+ data.tar.gz: 6f7450a9ecf65d6d32294f26142706a7c523af2073be90e9cb9bc6a630ae73f9
5
5
  SHA512:
6
- metadata.gz: 60dbd904786ddc419e9efbb0f02904c6035089a3b23fcb4035d41c85c8db303ae807138fa1e26c042688521c34a355f0314799e82addc73ef6308fc3fe6cad15
7
- data.tar.gz: ca1d3af3c319695cbb33e11f9f66a384efb2c1884a387a233d5b197ae9ed5d3a3852c49662586a67ba15eb497ed325b92363cfe65ce8e086c6319b48dfb0569e
6
+ metadata.gz: 0bab92c52ee0dd45b2893f1e592a480b53c055d2addd522d8ab22bdc8b83068983734974ba56aaf47d370dd6f42b342ec5e1cc8623f8e8a4833ccf112e23bdf2
7
+ data.tar.gz: f159851f5089686e1b767f53852257d10575bb4c532e603f8d3a9169f7500556a802bf0e79e60de19c6056d213347782a7334f6a67c5f9ec5f3bc9a2085c472f
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
+ ## [3.1.0] - 2024-09-09
17
+
18
+ ### Fixed
19
+
20
+ - Refactor consumer class initialization
21
+
16
22
  ## [3.0.0] - 2024-09-04
17
23
 
18
24
  ## BREAKING
@@ -25,6 +31,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
25
31
 
26
32
  - Support consumer group mappers to support backward compatibility of consumer group naming
27
33
 
34
+ ## [2.8.0] - 2024-09-09
35
+
36
+ ### Fixed
37
+
38
+ - Refactor consumer class initialization
39
+
28
40
  ## [2.7.1] - 2024-08-01
29
41
 
30
42
  ### 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 = "3.0.0"
5
+ VERSION = "3.1.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: 3.0.0
4
+ version: 3.1.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-05 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