如何通过 DelphiKafkaClient(或 librdkafka.dll)使用通配符订阅 Kafka 主题?
How to subscribe to Kafka topics using wildcards with DelphiKafkaClient (or librdkafka.dll)?
我正在使用 DelphiKafkaClient (https://github.com/norgepaul/DelphiKafkaClient),它是 Apache Kafka (librdkafka.dll) 的包装器。
创建新消费者并指定要订阅的主题名称时(TKafkaFactory.NewConsumer
),普通名称可以正常工作,但正则表达式通配符似乎不起作用(^*
,*
、#
、^.*
或其他任何内容)。
这里是 DelphiKafkaClient 的相关代码(见我的评论):
procedure TKafkaConsumerThread.DoSetup;
var
i: Integer;
TopicList: prd_kafka_topic_partition_list_t;
err: rd_kafka_resp_err_t;
begin
FKafkaHandle := TKafkaHelper.NewConsumer(FConfiguration);
if rd_kafka_brokers_add(FKafkaHandle, PAnsiChar(AnsiString(FBrokers))) = 0 then
begin
raise EKafkaError.Create(StrBrokersCouldNotBe);
end;
rd_kafka_poll_set_consumer(FKafkaHandle);
TopicList := rd_kafka_topic_partition_list_new(0);
for i := Low(FTopics) to High(FTopics) do
begin
rd_kafka_topic_partition_list_add(
TopicList,
PAnsiChar(AnsiString(FTopics[i])), // 'test' works, '^*' does not
FPartitions[i]);
end;
err := rd_kafka_assign(FKafkaHandle, TopicList); // no errors returned, all fine
// I have tried using rd_kafka_subscribe alongside or instead - makes no difference
err := rd_kafka_subscribe(FKafkaHandle, TopicList); // no errors returned, all fine
end;
rd_kafka_subscribe
描述说
Wildcard (regex) topics are supported:
any topic name in the \p topics list that is prefixed with \c "^" will
be regex-matched to the full list of topics in the cluster and matching
topics will be added to the subscription list.
但是,为其指定任何通配符并调用 rd_kafka_subscribe
似乎也不起作用(参见上面的代码)。
因此我的问题 - 应该如何格式化字符串并将其传递给 DelphiKafkaClient 或 librdkafka.dll 作为匹配主题订阅的有效正则表达式?
DelphiKafkaClient (https://github.com/norgepaul/DelphiKafkaClient) 带有一个非常古老的 DLL。将 DLL 从版本 0.9.2 升级到更新版本使 RegEx 正常工作。
我正在使用 DelphiKafkaClient (https://github.com/norgepaul/DelphiKafkaClient),它是 Apache Kafka (librdkafka.dll) 的包装器。
创建新消费者并指定要订阅的主题名称时(TKafkaFactory.NewConsumer
),普通名称可以正常工作,但正则表达式通配符似乎不起作用(^*
,*
、#
、^.*
或其他任何内容)。
这里是 DelphiKafkaClient 的相关代码(见我的评论):
procedure TKafkaConsumerThread.DoSetup;
var
i: Integer;
TopicList: prd_kafka_topic_partition_list_t;
err: rd_kafka_resp_err_t;
begin
FKafkaHandle := TKafkaHelper.NewConsumer(FConfiguration);
if rd_kafka_brokers_add(FKafkaHandle, PAnsiChar(AnsiString(FBrokers))) = 0 then
begin
raise EKafkaError.Create(StrBrokersCouldNotBe);
end;
rd_kafka_poll_set_consumer(FKafkaHandle);
TopicList := rd_kafka_topic_partition_list_new(0);
for i := Low(FTopics) to High(FTopics) do
begin
rd_kafka_topic_partition_list_add(
TopicList,
PAnsiChar(AnsiString(FTopics[i])), // 'test' works, '^*' does not
FPartitions[i]);
end;
err := rd_kafka_assign(FKafkaHandle, TopicList); // no errors returned, all fine
// I have tried using rd_kafka_subscribe alongside or instead - makes no difference
err := rd_kafka_subscribe(FKafkaHandle, TopicList); // no errors returned, all fine
end;
rd_kafka_subscribe
描述说
Wildcard (regex) topics are supported:
any topic name in the \p topics list that is prefixed with \c "^" will
be regex-matched to the full list of topics in the cluster and matching
topics will be added to the subscription list.
但是,为其指定任何通配符并调用 rd_kafka_subscribe
似乎也不起作用(参见上面的代码)。
因此我的问题 - 应该如何格式化字符串并将其传递给 DelphiKafkaClient 或 librdkafka.dll 作为匹配主题订阅的有效正则表达式?
DelphiKafkaClient (https://github.com/norgepaul/DelphiKafkaClient) 带有一个非常古老的 DLL。将 DLL 从版本 0.9.2 升级到更新版本使 RegEx 正常工作。