question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to setup default topic config for consumer and producer with topic auto creation?

See original GitHub issue

Description

Hello! At our team we use topics with auto creation on consumer subscription or producer publish. And we need to set default topic config for topic (at least setup cleanup policy and number of partitions). On some issues in this repo (f.e. https://github.com/confluentinc/confluent-kafka-dotnet/issues/861) i found some mentions about default.topic.config when configuration has type signature as IEnumerable<KeyValuePair<string, object>>. librdkafka have parameter in documentation to setup default topic config (default_topic_conf in https://github.com/edenhill/librdkafka/blob/master/CONFIGURATION.md). And now signature of config is more strongly typed with extra properties type signature as IEnumerable<KeyValuePair<string, string>> . I’ve tried to set ``default_topic_conf``` to config with dummy value and i’ve got:

System.ArgumentException : Property "default_topic_conf" must be set through dedicated .._set_..() function
   at Confluent.Kafka.Impl.SafeConfigHandle.Set(String name, String value)
   at Confluent.Kafka.Consumer`2.<>c__DisplayClass77_0.<.ctor>b__3(KeyValuePair`2 kvp)
   at System.Collections.Generic.List`1.ForEach(Action`1 action)
   at Confluent.Kafka.Consumer`2..ctor(ConsumerBuilder`2 builder)
   at Confluent.Kafka.ConsumerBuilder`2.Build()

Seems like I need to call librdkafka api to set it up but required configHandle is encapsulated in Consumer ctor: https://github.com/confluentinc/confluent-kafka-dotnet/blob/master/src/Confluent.Kafka/Consumer.cs#L676.

With default.topic.config:

System.InvalidOperationException : No such configuration property: "default.topic.config"
   at Confluent.Kafka.Impl.SafeConfigHandle.Set(String name, String value)
   at Confluent.Kafka.Consumer`2.<>c__DisplayClass77_0.<.ctor>b__3(KeyValuePair`2 kvp)
   at System.Collections.Generic.List`1.ForEach(Action`1 action)
   at Confluent.Kafka.Consumer`2..ctor(ConsumerBuilder`2 builder)
   at Confluent.Kafka.ConsumerBuilder`2.Build()

What is a correct way to set default topic config? And if at the moment its not available do you have any plans to support it?

  • Confluent.Kafka nuget version: 1.6.3
  • Apache Kafka version: 0.11.
  • Windows 10 Pro, Build 20H2

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
CrazyRyDmicommented, May 13, 2021

Thanks for explanation! Actually we use approach with explicit topic creation by wrapping Produce/Subscribe methods and calling something like EnsureTopicExistsAsync (which uses AdminClient) before corresponding methods with topic settings (server options like cleanup.policy). I think that its very convinient to use lazy topic initialization with custom config and without necessarity to use explicit checking about either topic already exists or not. Maybe this is not a bad idea to inlude feature like that into Confluent.Kafka in a future releases. What do you think about?

0reactions
CrazyRyDmicommented, May 14, 2021

Great! Thanks for your answers!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Customization of Kafka Connect automatic topic creation
Disabling automatic topic creation for the Kafka broker. By default, the Kafka broker configuration enables the broker to create topics at runtime if...
Read more >
How to create topics in apache kafka?
One of the properties is auto.create.topics.enable , if it's set to true (by default) Kafka will create topics automatically when you send ...
Read more >
Manage Kafka Cluster and Topic Configuration Settings in ...
This topic describes the default Apache Kafka® cluster and topic configuration settings in Confluent Cloud as well as the topic settings that can...
Read more >
Kafka topic configuration reference
This topic provides topic-level configuration parameters available for Confluent Platform. The Kafka topic configuration parameters are listed in alphabetical ...
Read more >
KIP-487: Client-side Automatic Topic Creation on Producer
The idea is to move the configuration and ability to automatically create topics client-side on the producer. Broker auto-topic creation ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found