Skip to content

Commit

Permalink
Improve docs for @KafkaClient/@KafkaListener behavior (#657)
Browse files Browse the repository at this point in the history
  • Loading branch information
MT-Jacobs authored Feb 9, 2023
1 parent 6c992a1 commit e6e4f6e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/main/docs/guide/kafkaClient/kafkaClientConfiguration.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ kafka:
producers:
default:
retries: 5
bootstrap:
servers: localhost:9096
----

Any property in the link:{kafkaapi}/org/apache/kafka/clients/producer/ProducerConfig.html[ProducerConfig] class can be set. The above example will set the default number of times to retry sending a record.
Any property in the link:{kafkaapi}/org/apache/kafka/clients/producer/ProducerConfig.html[ProducerConfig] class can be set, _including_ any overrides over the global Micronaut Kafka configs. The above example will set the default number of times to retry sending a record as well as override `kafka.bootstrap.servers`.

=== Per @KafkaClient Producer Properties

Expand All @@ -32,6 +35,11 @@ kafka:
producers:
product-client:
retries: 5
bootstrap:
servers: localhost:9097
product-client-2:
bootstrap:
servers: localhost:9098
----

Finally, the ann:configuration.kafka.annotation.KafkaClient[] annotation itself provides a `properties` member that you can use to set producer specific properties:
Expand Down
14 changes: 14 additions & 0 deletions src/main/docs/guide/kafkaListener.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,17 @@ The above example will create 10 link:{kafkaapi}/org/apache/kafka/clients/consum
NOTE: @KafkaListener beans are by default singleton. When using multiple threads you must either synchronize access to local state or declare the bean as `@Prototype`.

By default Micronaut will inspect the method signature of the method annotated with `@Topic` that will listen for `ConsumerRecord` instances and from the types infer an appropriate key and value link:{kafkaapi}/org/apache/kafka/common/serialization/Deserializer.html[Deserializer].

.Applying Configuration
[source,yaml]
----
kafka:
consumers:
default:
allow.auto.create.topics: true
product:
bootstrap:
servers: localhost:9098
----

Any property in the link:{kafkaapi}\/org/apache/kafka/clients/consumer/ConsumerConfig.html[ConsumerConfig] class can be set for all `@KafkaListener` beans based on the . The above example will enable the consumer to create a topic if it doesn't exist for the `default` (`@KafkaListener`) client and set a custom bootstrap server for the `product` client (`@KafkaListener(value = "product")`)

0 comments on commit e6e4f6e

Please sign in to comment.