Skip to content

Commit

Permalink
feat: support custom kafka group id prefix
Browse files Browse the repository at this point in the history
Signed-off-by: xxchan <[email protected]>
  • Loading branch information
xxchan committed Aug 20, 2024
1 parent 0595aa1 commit 2da639f
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 3 deletions.
44 changes: 42 additions & 2 deletions e2e_test/source_inline/kafka/consumer_group.slt
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,23 @@ WITH(
scan.startup.mode = 'earliest',
) FORMAT PLAIN ENCODE JSON;

# custom group id prefix
statement ok
CREATE SOURCE s2(x varchar)
WITH(
${RISEDEV_KAFKA_WITH_OPTIONS_COMMON},
topic = 'test_consumer_group',
scan.startup.mode = 'earliest',
group.id.prefix = 'my_group'
) FORMAT PLAIN ENCODE JSON;


statement ok
CREATE MATERIALIZED VIEW mv AS SELECT * from s;

statement ok
CREATE MATERIALIZED VIEW mv2 AS SELECT * from s2;

query ?
SELECT * FROM s order by x;
----
Expand Down Expand Up @@ -87,11 +101,37 @@ d
e
f


query ?
SELECT * FROM mv2 order by x;
----
a
b
c
d
e
f


statement ok
DROP SOURCE s CASCADE;

statement ok
DROP SOURCE s2 CASCADE;

## fragment id is not deterministic so comment out
# system ok
# rpk group list
# ---
# BROKER GROUP STATE
# 0 my_group-8 Empty
# 0 rw-consumer-3 Empty
# 0 rw-consumer-4294967295 Empty
# 0 rw-consumer-7 Empty


system ok
pkill rpk

system ok
rpk topic delete test_consumer_group
# system ok
# rpk topic delete test_consumer_group
1 change: 1 addition & 0 deletions src/connector/src/sink/kafka.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ impl From<KafkaConfig> for KafkaProperties {
rdkafka_properties_consumer: Default::default(),
privatelink_common: val.privatelink_common,
aws_auth_props: val.aws_auth_props,
group_id_prefix: None,
unknown_fields: Default::default(),
}
}
Expand Down
14 changes: 14 additions & 0 deletions src/connector/src/source/kafka/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,20 @@ pub struct KafkaProperties {
)]
pub time_offset: Option<String>,

/// Specify a custom consumer group id prefix for the source.
/// Defaults to `rw-consumer`.
///
/// Notes:
/// - Each job (materialized view) will have a separated consumer group and
/// contains a generated suffix in the group id.
/// The consumer group will be `{group_id_prefix}-{fragment_id}`.
/// - The consumer group is solely for monintoring progress in some external
/// Kafka tools, and for authorization. RisingWave does not rely on committed
/// offsets, and does not join the consumer group. It just reports offsets
/// to the group.
#[serde(rename = "group.id.prefix")]
pub group_id_prefix: Option<String>,

/// This parameter is used to tell `KafkaSplitReader` to produce `UpsertMessage`s, which
/// combine both key and value fields of the Kafka message.
/// TODO: Currently, `Option<bool>` can not be parsed here.
Expand Down
6 changes: 5 additions & 1 deletion src/connector/src/source/kafka/source/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,13 @@ impl SplitReader for KafkaSplitReader {
properties.common.set_security_properties(&mut config);
properties.set_client(&mut config);

let group_id_prefix = properties
.group_id_prefix
.as_deref()
.unwrap_or("rw-consumer");
config.set(
"group.id",
format!("rw-consumer-{}", source_ctx.fragment_id),
format!("{}-{}", group_id_prefix, source_ctx.fragment_id),
);

let ctx_common = KafkaContextCommon::new(
Expand Down

0 comments on commit 2da639f

Please sign in to comment.