karafka 2.0.19 → 2.0.20

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: be91c3848b757c6af4c25f905df2b081629532bd29dbcea23ed2ef0af2e4e4a2
4
- data.tar.gz: 6823d4335e4b395546642101d6754b97958c86810cbcd12819559acff74bd90d
3
+ metadata.gz: c3b857c4c930396d4cac4682e4350c4c5fdc2888128dfade3f06e21a02e90c29
4
+ data.tar.gz: 4f8fdb66df24164ec65886d5b4c4ba766dda9c7d4d23a7a301920a8adb21e16e
5
5
  SHA512:
6
- metadata.gz: fce0259ee987e37c01ea037f81ea91b4eb770ea8eabcb9f93c66aa1a1960c903030648b5441945ef28f43a88660d18240e6db61f6885a169d70eb46174543616
7
- data.tar.gz: f93985c98daba5965f8f0597da4744d1dae0603f24a6a44f4b337462f66c8b0f08d0c22dd734205a0aebe7c3dbdb73237ff568f7f1ff842b38c05a7f4b5ce463
6
+ metadata.gz: d4ed9d036f7dae85b3ce2f9c45de64eed8a8da110f0a826baf100ec9c90dc7e7dbaf5c74f89b472eb89ee7d3bdc9e265fee259621d93e21c972776fa3f682cc0
7
+ data.tar.gz: aed5fcd7447be757cd2ca641d1d4f6029db11296ac6b4012b4a02047126f27be4aef8d42da700f736c4f70eba2b0aff252a4ccf332fb6c8b88e6a911e3432171
checksums.yaml.gz.sig CHANGED
Binary file
@@ -0,0 +1 @@
1
+ custom: ['https://karafka.io/#become-pro']
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Karafka framework changelog
2
2
 
3
+ ## 2.0.20 (2022-11-24)
4
+ - [Improvement] Support `group.instance.id` assignment (static group membership) for a case where a single consumer group has multiple subscription groups (#1173).
5
+
3
6
  ## 2.0.19 (2022-11-20)
4
7
  - **[Feature]** Provide ability to skip failing messages without dispatching them to an alternative topic (DLQ).
5
8
  - [Improvement] Improve the integration with Ruby on Rails by preventing double-require of components.
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- karafka (2.0.19)
5
- karafka-core (>= 2.0.2, < 3.0.0)
4
+ karafka (2.0.20)
5
+ karafka-core (>= 2.0.4, < 3.0.0)
6
6
  rdkafka (>= 0.12)
7
7
  thor (>= 0.20)
8
8
  waterdrop (>= 2.4.1, < 3.0.0)
@@ -30,7 +30,7 @@ GEM
30
30
  activesupport (>= 5.0)
31
31
  i18n (1.12.0)
32
32
  concurrent-ruby (~> 1.0)
33
- karafka-core (2.0.3)
33
+ karafka-core (2.0.4)
34
34
  concurrent-ruby (>= 1.1)
35
35
  mini_portile2 (2.8.0)
36
36
  minitest (5.16.3)
data/karafka.gemspec CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
16
16
  spec.description = 'Framework used to simplify Apache Kafka based Ruby applications development'
17
17
  spec.licenses = ['LGPL-3.0', 'Commercial']
18
18
 
19
- spec.add_dependency 'karafka-core', '>= 2.0.2', '< 3.0.0'
19
+ spec.add_dependency 'karafka-core', '>= 2.0.4', '< 3.0.0'
20
20
  spec.add_dependency 'rdkafka', '>= 0.12'
21
21
  spec.add_dependency 'thor', '>= 0.20'
22
22
  spec.add_dependency 'waterdrop', '>= 2.4.1', '< 3.0.0'
@@ -16,11 +16,6 @@ module Karafka
16
16
  class ConsumerGroupCoordinator
17
17
  # @param group_size [Integer] number of separate subscription groups in a consumer group
18
18
  def initialize(group_size)
19
- # We need two locks here:
20
- # - first one is to decrement the number of listeners doing work
21
- # - second to ensure only one client is being closed the same time and that others can
22
- # wait actively (not locked)
23
- @work_mutex = Mutex.new
24
19
  @shutdown_lock = Mutex.new
25
20
  @group_size = group_size
26
21
  @finished = Set.new
@@ -40,6 +40,9 @@ module Karafka
40
40
  consumer_group.topics.each do |topic|
41
41
  Contracts::Topic.new.validate!(topic.to_h)
42
42
  end
43
+
44
+ # Initialize subscription groups after all the routing is done
45
+ consumer_group.subscription_groups
43
46
  end
44
47
  end
45
48
 
@@ -14,7 +14,7 @@ module Karafka
14
14
  # It allows us to store the "current" subscription group defined in the routing
15
15
  # This subscription group id is then injected into topics, so we can compute the subscription
16
16
  # groups
17
- attr_accessor :current_subscription_group_name
17
+ attr_accessor :current_subscription_group_id
18
18
 
19
19
  # @param name [String, Symbol] raw name of this consumer group. Raw means, that it does not
20
20
  # yet have an application client_id namespace, this will be added here by default.
@@ -24,6 +24,9 @@ module Karafka
24
24
  @name = name.to_s
25
25
  @id = Karafka::App.config.consumer_mapper.call(name)
26
26
  @topics = Topics.new([])
27
+ # Initialize the subscription group so there's always a value for it, since even if not
28
+ # defined directly, a subscription group will be created
29
+ @current_subscription_group_id = SecureRandom.uuid
27
30
  end
28
31
 
29
32
  # @return [Boolean] true if this consumer group should be active in our current process
@@ -41,7 +44,7 @@ module Karafka
41
44
  built_topic = @topics.last
42
45
  # We overwrite it conditionally in case it was not set by the user inline in the topic
43
46
  # block definition
44
- built_topic.subscription_group ||= current_subscription_group_name
47
+ built_topic.subscription_group ||= current_subscription_group_id
45
48
  built_topic
46
49
  end
47
50
 
@@ -52,19 +55,24 @@ module Karafka
52
55
  def subscription_group=(name, &block)
53
56
  # We cast it here, so the routing supports symbol based but that's anyhow later on
54
57
  # validated as a string
55
- self.current_subscription_group_name = name
58
+ @current_subscription_group_id = name
56
59
 
57
60
  Proxy.new(self, &block)
58
61
 
59
62
  # We need to reset the current subscription group after it is used, so it won't leak
60
63
  # outside to other topics that would be defined without a defined subscription group
61
- self.current_subscription_group_name = nil
64
+ @current_subscription_group_id = SecureRandom.uuid
62
65
  end
63
66
 
64
67
  # @return [Array<Routing::SubscriptionGroup>] all the subscription groups build based on
65
68
  # the consumer group topics
66
69
  def subscription_groups
67
- App.config.internal.routing.subscription_groups_builder.call(topics)
70
+ @subscription_groups ||= App
71
+ .config
72
+ .internal
73
+ .routing
74
+ .subscription_groups_builder
75
+ .call(topics)
68
76
  end
69
77
 
70
78
  # Hashed version of consumer group that can be used for validation purposes
@@ -8,13 +8,18 @@ module Karafka
8
8
  # @note One subscription group will always belong to one consumer group, but one consumer
9
9
  # group can have multiple subscription groups.
10
10
  class SubscriptionGroup
11
- attr_reader :id, :topics
11
+ attr_reader :id, :topics, :kafka
12
12
 
13
+ # @param position [Integer] position of this subscription group in all the subscriptions
14
+ # groups array. We need to have this value for sake of static group memberships, where
15
+ # we need a "in-between" restarts unique identifier
13
16
  # @param topics [Karafka::Routing::Topics] all the topics that share the same key settings
14
17
  # @return [SubscriptionGroup] built subscription group
15
- def initialize(topics)
16
- @id = SecureRandom.uuid
18
+ def initialize(position, topics)
19
+ @id = "#{topics.first.subscription_group}_#{position}"
20
+ @position = position
17
21
  @topics = topics
22
+ @kafka = build_kafka
18
23
  freeze
19
24
  end
20
25
 
@@ -33,12 +38,22 @@ module Karafka
33
38
  @topics.first.max_wait_time
34
39
  end
35
40
 
41
+ private
42
+
36
43
  # @return [Hash] kafka settings are a bit special. They are exactly the same for all of the
37
44
  # topics but they lack the group.id (unless explicitly) provided. To make it compatible
38
45
  # with our routing engine, we inject it before it will go to the consumer
39
- def kafka
46
+ def build_kafka
40
47
  kafka = Setup::AttributesMap.consumer(@topics.first.kafka.dup)
41
48
 
49
+ # If we use static group memberships, there can be a case, where same instance id would
50
+ # be set on many subscription groups as the group instance id from Karafka perspective is
51
+ # set per config. Each instance even if they are subscribed to different topics needs to
52
+ # have if fully unique. To make sure of that, we just add extra postfix at the end that
53
+ # increments.
54
+ group_instance_id = kafka.fetch(:'group.instance.id', false)
55
+
56
+ kafka[:'group.instance.id'] = "#{group_instance_id}_#{@position}" if group_instance_id
42
57
  kafka[:'client.id'] ||= Karafka::App.config.client_id
43
58
  kafka[:'group.id'] ||= @topics.first.consumer_group.id
44
59
  kafka[:'auto.offset.reset'] ||= @topics.first.initial_offset
@@ -24,6 +24,10 @@ module Karafka
24
24
 
25
25
  private_constant :DISTRIBUTION_KEYS
26
26
 
27
+ def initialize
28
+ @position = -1
29
+ end
30
+
27
31
  # @param topics [Karafka::Routing::Topics] all the topics based on which we want to build
28
32
  # subscription groups
29
33
  # @return [Array<SubscriptionGroup>] all subscription groups we need in separate threads
@@ -34,7 +38,7 @@ module Karafka
34
38
  .values
35
39
  .map { |value| value.map(&:last) }
36
40
  .map { |topics_array| Routing::Topics.new(topics_array) }
37
- .map { |grouped_topics| SubscriptionGroup.new(grouped_topics) }
41
+ .map { |grouped_topics| SubscriptionGroup.new(@position += 1, grouped_topics) }
38
42
  end
39
43
 
40
44
  private
@@ -3,5 +3,5 @@
3
3
  # Main module namespace
4
4
  module Karafka
5
5
  # Current Karafka version
6
- VERSION = '2.0.19'
6
+ VERSION = '2.0.20'
7
7
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: karafka
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.19
4
+ version: 2.0.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maciej Mensfeld
@@ -35,7 +35,7 @@ cert_chain:
35
35
  Qf04B9ceLUaC4fPVEz10FyobjaFoY4i32xRto3XnrzeAgfEe4swLq8bQsR3w/EF3
36
36
  MGU0FeSV2Yj7Xc2x/7BzLK8xQn5l7Yy75iPF+KP3vVmDHnNl
37
37
  -----END CERTIFICATE-----
38
- date: 2022-11-20 00:00:00.000000000 Z
38
+ date: 2022-11-24 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: karafka-core
@@ -43,7 +43,7 @@ dependencies:
43
43
  requirements:
44
44
  - - ">="
45
45
  - !ruby/object:Gem::Version
46
- version: 2.0.2
46
+ version: 2.0.4
47
47
  - - "<"
48
48
  - !ruby/object:Gem::Version
49
49
  version: 3.0.0
@@ -53,7 +53,7 @@ dependencies:
53
53
  requirements:
54
54
  - - ">="
55
55
  - !ruby/object:Gem::Version
56
- version: 2.0.2
56
+ version: 2.0.4
57
57
  - - "<"
58
58
  - !ruby/object:Gem::Version
59
59
  version: 3.0.0
@@ -130,6 +130,7 @@ files:
130
130
  - ".coditsu/ci.yml"
131
131
  - ".console_irbrc"
132
132
  - ".diffend.yml"
133
+ - ".github/FUNDING.yml"
133
134
  - ".github/ISSUE_TEMPLATE/bug_report.md"
134
135
  - ".github/ISSUE_TEMPLATE/feature_request.md"
135
136
  - ".github/workflows/ci.yml"
metadata.gz.sig CHANGED
Binary file