-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Reference Doc Improvements #2867
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
[[connecting]] | ||
= Connecting to Kafka | ||
|
||
* `KafkaAdmin` - see <<configuring-topics>> | ||
* `KafkaAdmin` - see xref:kafka/configuring-topics.adoc[Configuring Topics] | ||
* `ProducerFactory` - see xref:kafka/sending-messages.adoc[Sending Messages] | ||
* `ConsumerFactory` - see xref:kafka/receiving-messages.adoc[Receiving Messages] | ||
|
||
Starting with version 2.5, each of these extends `KafkaResourceFactory`. | ||
This allows changing the bootstrap servers at runtime by adding a `Supplier<String>` to their configuration: `setBootstrapServersSupplier(() -> ...)`. | ||
This allows changing the bootstrap servers at runtime by adding a `Supplier<String>` to their configuration: `setBootstrapServersSupplier(() +++->+++ ...)`. | ||
This will be called for all new connections to get the list of servers. | ||
Consumers and Producers are generally long-lived. | ||
To close existing Producers, call `reset()` on the `DefaultKafkaProducerFactory`. | ||
|
@@ -15,7 +15,7 @@ To close existing Consumers, call `stop()` (and then `start()`) on the `KafkaLis | |
For convenience, the framework also provides an `ABSwitchCluster` which supports two sets of bootstrap servers; one of which is active at any time. | ||
Configure the `ABSwitchCluster` and add it to the producer and consumer factories, and the `KafkaAdmin`, by calling `setBootstrapServersSupplier()`. | ||
When you want to switch, call `primary()` or `secondary()` and call `reset()` on the producer factory to establish new connection(s); for consumers, `stop()` and `start()` all listener containers. | ||
When using `@KafkaListener` s, `stop()` and `start()` the `KafkaListenerEndpointRegistry` bean. | ||
When using `@KafkaListener`+++s+++, `stop()` and `start()` the `KafkaListenerEndpointRegistry` bean. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
See the Javadocs for more information. | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,20 +29,20 @@ | |
// tag::startedNoBootSender[] | ||
public class Sender { | ||
|
||
public static void main(String[] args) { | ||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class); | ||
context.getBean(Sender.class).send("test", 42); | ||
} | ||
public static void main(String[] args) { | ||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class); | ||
context.getBean(Sender.class).send("test", 42); | ||
} | ||
|
||
private final KafkaTemplate<Integer, String> template; | ||
private final KafkaTemplate<Integer, String> template; | ||
|
||
public Sender(KafkaTemplate<Integer, String> template) { | ||
this.template = template; | ||
} | ||
public Sender(KafkaTemplate<Integer, String> template) { | ||
this.template = template; | ||
} | ||
|
||
public void send(String toSend, int key) { | ||
this.template.send("topic1", key, toSend); | ||
} | ||
public void send(String toSend, int key) { | ||
this.template.send("topic1", key, toSend); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
} | ||
// end::startedNoBootSender[] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,8 +16,8 @@ | |
|
||
package org.springframework.kafka.jdocs.topics; | ||
|
||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.apache.kafka.clients.admin.AdminClientConfig; | ||
|
@@ -67,9 +67,9 @@ public NewTopic topic2() { | |
@Bean | ||
public NewTopic topic3() { | ||
return TopicBuilder.name("thing3") | ||
.assignReplicas(0, Arrays.asList(0, 1)) | ||
.assignReplicas(1, Arrays.asList(1, 2)) | ||
.assignReplicas(2, Arrays.asList(2, 0)) | ||
.assignReplicas(0, List.of(0, 1)) | ||
.assignReplicas(1, List.of(1, 2)) | ||
.assignReplicas(2, List.of(2, 0)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not necessary, but we have used Java 17, why not use the handy collection constant feature introduced since Java 9? |
||
.config(TopicConfig.COMPRESSION_TYPE_CONFIG, "zstd") | ||
.build(); | ||
} | ||
|
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 special char in AsciiDoc, so we could use +++ to render it literally