-
Notifications
You must be signed in to change notification settings - Fork 41.2k
Add Kafka AutoConfiguration #6961
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
@@ -0,0 +1 @@ | |||
Test file for Kafka. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test file
But it is somehow in the main
...
c3927ac
to
93494a3
Compare
Hi @garyrussell , @artembilan Just spotted this pull request. What would you recommend regarding the metrics which I've talked about before? |
@stepio , Glad to hear from you back again! As you see this Kafka auto-configuration hasn't been merged yet. Thank you for the contribution as usual! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @garyrussell thanks for the PR! I've added some comments and I am happy to process them myself but as I am quite new to Kafka I want to make sure I didn't overlook something first.
*/ | ||
public void setKafkaProperties(KafkaProperties properties) { | ||
this.properties = properties; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason why this is not set via constructor injection? If you make the link with the JMS part we had a bunch of components that might be responsible of tuning the factory and we didn't want to offer a way to users to modify the configurer once it has been created. That's why they are package protected (this one is public).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I based this on the amqp auto config but I missed that it has package protection for these methods.
@ConditionalOnMissingBean(KafkaTemplate.class) | ||
public KafkaTemplate<?, ?> kafkaTemplate(ProducerFactory<Object, Object> kafkaProducerFactory, | ||
ProducerListener<Object, Object> kafkaProducerListener) { | ||
KafkaTemplate<Object, Object> kafkaTemplate = new KafkaTemplate<Object, Object>(kafkaProducerFactory); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is having more than one ProducerFactory
and/or ProducerListener
a common thing? If that's the case, can we please switch to a pattern where we use @ConditionalOnSingleCandidate
? you'll need a custom condition if you want to apply that to the two instances. If that does not make sense to have more than one instance of those, the code is fine as is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it wouldn't be common, unless you are talking to two or more distinct kafka clusters (which would need all the other configs as well). In fact, kafka recommends a single producer instance per JVM (which is what the default factory serves up).
* A comma-delimited list of host:port pairs to use for establishing the initial | ||
* connection to the Kafka cluster. | ||
*/ | ||
private List<String> bootstrapServers = Collections.singletonList("localhost:9092"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you need to wrap that in a new ArrayList
otherwise access by key won't work (the initial collection is immutable).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure what you mean by "access by key" but I can add the wrapper.
/** | ||
* The password of the private key in the key store file. | ||
*/ | ||
private String sslKeyPassword; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have a ssl
namespace for these (see RabbitProperties
for instance)
private String clientId; | ||
|
||
/** | ||
* The password of the private key in the key store file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Meta-data description never starts with The
, A
, etc. Could you please align the documentation of those keys so that they match what we already have?
/** | ||
* The password of the private key in the key store file. | ||
*/ | ||
private String sslKeyPassword; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reuse the Ssl
object there?
/** | ||
* The store password for the trust store file. | ||
*/ | ||
private String sslTruststorePassword; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ssl
object again?
"spring.kafka.listener.concurrency=3", | ||
"spring.kafka.listener.poll-timeout=2000" | ||
}) | ||
public class KafkaPropertiesTests { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Such Properties
object are rather tested as simple unit test, using EnvironmentContextTestUtils
to bind the relevant keys.
# Apache Kafka designates properties with an importance: HIGH, MEDIUM and LOW. | ||
# Spring Boot auto configuration supports all HIGH importance properties, some selected MEDIUM and LOW, | ||
# and any that do not have a default value. | ||
# To set additional properties, override the consumer and/or producer factory beans; see <<kafka-extra-props>>. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather see that text in the documentation itself. We really intend this appendix to only list the keys and their documentation (we have the intend to actually auto-generate it).
@@ -4499,7 +4499,77 @@ Here's an example of a customizer that configures the use of a proxy for all hos | |||
include::{code-examples}/web/client/RestTemplateProxyCustomizationExample.java[tag=customizer] | |||
---- | |||
|
|||
[[boot-features-kafka]] | |||
== Apache Kafka |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason why it's not located under the messaging
section?
Change Common Props to Hyphenated (asciidoc) Only Support HIGH and a Few Other Props
93494a3
to
dc114aa
Compare
* pr/6961: Polish "Apache Kafka support" contribution Add Apache Kafka support
Replaces #5516
Change Common Props to Hyphenated (asciidoc)
Only Support HIGH and a Few Other Props