@@ -77,6 +77,9 @@ def initialize(cluster:, logger:, instrumenter:, group:, fetcher:, offset_manage
77
77
# Hash storing topics that are already being subscribed
78
78
# When subcribing to a new topic, if it's already being subscribed before, skip it
79
79
@subscribed_topics = Set . new
80
+
81
+ # Whether join_group must be executed again because new topics are added
82
+ @join_group_for_new_topics = false
80
83
end
81
84
82
85
# Subscribes the consumer to a topic.
@@ -489,6 +492,7 @@ def join_group
489
492
end
490
493
491
494
@fetcher . reset
495
+ @join_group_for_new_topics = false
492
496
493
497
@group . assigned_partitions . each do |topic , partitions |
494
498
partitions . each do |partition |
@@ -534,7 +538,7 @@ def fetch_batches
534
538
# Return early if the consumer has been stopped.
535
539
return [ ] if shutting_down?
536
540
537
- join_group unless @group . member?
541
+ join_group if ! @group . member? || @join_group_for_new_topics
538
542
539
543
trigger_heartbeat
540
544
@@ -597,6 +601,7 @@ def subscribe_to_regex(topic_regex, default_offset, start_from_beginning, max_by
597
601
def subscribe_to_topic ( topic , default_offset , start_from_beginning , max_bytes_per_partition )
598
602
return if @subscribed_topics . include? ( topic )
599
603
@subscribed_topics . add ( topic )
604
+ @join_group_for_new_topics = true
600
605
601
606
@group . subscribe ( topic )
602
607
@offset_manager . set_default_offset ( topic , default_offset )
0 commit comments