I am using confluent golang for my Kafka client. I use AdminClient
to create/delete/get topics in kafka cluster. Here is my code to initialize AdminClient
adminClient, err := kafka.NewAdminClient(&kafka.ConfigMap{
"bootstrap.servers": 127.0.0.1:9092,
})
After that, I use this class to create and get all topics in kafka cluster. Here is the code for creating a topic:
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
results, err := adminClient.CreateTopics(
ctx,
[]kafka.TopicSpecification{{
Topic: topic,
NumPartitions: numPartitions,
ReplicationFactor: replicationFactor}},
kafka.SetAdminOperationTimeout(TimeOut),
)
After that, I get again topic information:
result, err := adminClient.GetMetadata(&topic, false, 1000)
The problem is: If I get a topic that not existed before, kafka will automatically create that topic. This is a behavior that I don't want. Please tell me how to fix this.