Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow @Override of KafkaAdmin createAdmin() #3483

Open
anders-swanson opened this issue Sep 13, 2024 · 3 comments · May be fixed by #3484
Open

Allow @Override of KafkaAdmin createAdmin() #3483

anders-swanson opened this issue Sep 13, 2024 · 3 comments · May be fixed by #3484

Comments

@anders-swanson
Copy link

anders-swanson commented Sep 13, 2024

Expected Behavior

The Spring KafkaAdmin class has a package-private method "createAdmin" that returns the org.apache.kafka.clients.admin.AdminClient type:

AdminClient createAdmin() {
    return AdminClient.create(this.getAdminConfig());
}

It'd be great if this method was protected, and returned the org.apache.kafka.clients.admin.Admin type. Additionally, the code in KafkaAdmin would need to be updated to use the Admin interface, instead of the KafkaAdmin class.

It's currently possible to do something similar the default producer/consumer factories, as they have methods like this:

	protected Consumer<K, V> createKafkaConsumer(Map<String, Object> configProps) {
		checkBootstrap(configProps);
		Consumer<K, V> kafkaConsumer = createRawConsumer(configProps);
		if (!this.listeners.isEmpty() && !(kafkaConsumer instanceof ExtendedKafkaConsumer)) {
			LOGGER.warn("The 'ConsumerFactory.Listener' configuration is ignored " +
					"because the consumer is not an instance of 'ExtendedKafkaConsumer'." +
					"Consider extending 'ExtendedKafkaConsumer' or implement your own 'ConsumerFactory'.");
		}

		for (ConsumerPostProcessor<K, V> pp : this.postProcessors) {
			kafkaConsumer = pp.apply(kafkaConsumer);
		}
		return kafkaConsumer;
	}

Current Behavior

KafkaAdmin cannot be extended/overridden to use another type of class implementing the org.apache.kafka.clients.admin.Admin interface.

Context

I'm using OKafka, which has implementations of the Kafka interfaces, e.g., the Admin interface, and I would like to use these implementations with Spring Kafka. Based on my understanding of the code, some modifications would need to be made as described - I'd also be interested in any workarounds, if they are available.

@anders-swanson anders-swanson changed the title Spring KafkaAdmin needs override method for providing the Kafka Admin Allow @Override of KafkaAdmin createAdmin() Sep 13, 2024
anders-swanson added a commit to anders-swanson/spring-kafka that referenced this issue Sep 13, 2024
@sobychacko
Copy link
Contributor

@anders-swanson I think this is a reasonable request. In these cases, we usually recommend providing the correct bootstrap server config to KafkaAdmin as long as you are still using the default AdminClient from the Kafka client. But since you are using a completely different Admin implementation, it makes sense to override that method. We will discuss this further and give an update here. Thanks!

@anders-swanson
Copy link
Author

@sobychacko thanks! I created #3484 and ran a few tests against it, seems like it has potential.

@sobychacko
Copy link
Contributor

That's great. We will review it and get back to you.

@sobychacko sobychacko added this to the 3.3.0-RC1 milestone Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants