Add Apache Kafka support
See gh-6961
This commit is contained in:
committed by
Stephane Nicoll
parent
9423b9831c
commit
c4188c8e4a
@@ -856,6 +856,55 @@ content into your application; rather pick only the properties that you need.
|
||||
spring.jms.template.receive-timeout= # Timeout to use for receive calls in milliseconds.
|
||||
spring.jms.template.time-to-live= # Time-to-live of a message when sending in milliseconds. Enable QoS when set.
|
||||
|
||||
# APACHE KAFKA ({sc-spring-boot-autoconfigure}/kafka/KafkaProperties.{sc-ext}[KafkaProperties])
|
||||
spring.kafka.bootstrap-servers=localhost:9092 # Comma-delimited list of host:port pairs.
|
||||
spring.kafka.client-id= # Id to pass to the server when making requests; used for server-side logging.
|
||||
spring.kafka.ssl.key-password= # Password of the private key in the key store file.
|
||||
spring.kafka.ssl.keystore-location= # Location (resource) of the key store file (e.g. file:my.ks).
|
||||
spring.kafka.ssl.keystore-password= # Store password for the key store file.
|
||||
spring.kafka.ssl.truststore-location= # Location (resource) of the trust store file (e.g. file:my.ts).
|
||||
spring.kafka.ssl.truststore-password= # Store password for the trust store file.
|
||||
# Consumer-specific properties:
|
||||
spring.kafka.consumer.auto-commit-interval-ms= # Frequency in milliseconds that the consumer offsets are auto-committed.
|
||||
spring.kafka.consumer.auto-offset-reset= # What to do when there is no initial offset in Kafka or if the current offset does not exist any more on the server.
|
||||
spring.kafka.consumer.bootstrap-servers= # Comma-delimited list of host:port pairs.
|
||||
spring.kafka.consumer.client-id= # Id to pass to the server when making requests; used for server-side logging.
|
||||
spring.kafka.consumer.enable-auto-commit= # If true the consumer's offset will be periodically committed in the background.
|
||||
spring.kafka.consumer.fetch-max-wait-ms= # Maximum amount of time the server will block before answering the fetch request.
|
||||
spring.kafka.consumer.fetch-min-bytes= # Minimum amount of data the server should return for a fetch request.
|
||||
spring.kafka.consumer.group-id= # Unique string that identifies the consumer group this consumer belongs to.
|
||||
spring.kafka.consumer.heartbeat-interval-ms= # Expected time between heartbeats to the consumer coordinator.
|
||||
spring.kafka.consumer.key-deserializer=StringDeserializer # Deserializer class for keys.
|
||||
spring.kafka.consumer.ssl.key-password= # Password of the private key in the key store file.
|
||||
spring.kafka.consumer.ssl.keystore-location= # Location (resource) of the key store file (e.g. file:my.ks).
|
||||
spring.kafka.consumer.ssl.keystore-password= # Store password for the key store file.
|
||||
spring.kafka.consumer.ssl.truststore-location= # Location (resource) of the trust store file (e.g. file:my.ts).
|
||||
spring.kafka.consumer.ssl.truststore-password= # Store password for the trust store file.
|
||||
spring.kafka.consumer.value-deserializer=StringDeserializer # Deserializer class for values.
|
||||
# Listener properties - Refer to the Spring for Apache Kafka documentation
|
||||
spring.kafka.listener.ack-mode=BATCH # AckMode - see the spring-kafka documentation.
|
||||
spring.kafka.listener.ack-count= # Number of records between offset commits when ack-mode is COUNT or COUNT_TIME.
|
||||
spring.kafka.listener.ack-time= # Time in milliseconds between offset commits when ack-mode is TIME or COUNT_TIME.
|
||||
spring.kafka.listener.concurrency=1 # Number of threads to run in the listener container(s).
|
||||
spring.kafka.listener.pollTimeout=1000 # Timeout in milliseconds to use when polling the consumer.
|
||||
# Producer-specific properties:
|
||||
spring.kafka.producer.acks= # Number of acknowledgments the producer requires the leader to have received.
|
||||
spring.kafka.producer.batch-size= # Number of records to batch before sending.
|
||||
spring.kafka.producer.bootstrap-servers= # Comma-delimited list of host:port pairs.
|
||||
spring.kafka.producer.buffer-memory= # Total bytes of memory the producer can use to buffer records waiting to be sent to the server.
|
||||
spring.kafka.producer.client-id= # Id to pass to the server when making requests; used for server-side logging.
|
||||
spring.kafka.producer.compression-type= # Compression type for all data generated by the producer.
|
||||
spring.kafka.producer.key-serializer=StringSerializer # Serializer class for keys.
|
||||
spring.kafka.producer.retries= # When greater than zero, enables retrying of failed sends.
|
||||
spring.kafka.producer.ssl.key-password= # Password of the private key in the key store file.
|
||||
spring.kafka.producer.ssl.keystore-location= # Location (resource) of the key store file (e.g. file:my.ks).
|
||||
spring.kafka.producer.ssl.keystore-password= # Store password for the key store file.
|
||||
spring.kafka.producer.ssl.truststore-location= # Location (resource) of the trust store file (e.g. file:my.ts).
|
||||
spring.kafka.producer.ssl.truststore-password= # Store password for the trust store file.
|
||||
spring.kafka.producer.value-serializer=StringSerializer # Serializer class for values.
|
||||
# template properties
|
||||
spring.kafka.template.default-topic= # Default topic to which messages are sent
|
||||
|
||||
# RABBIT ({sc-spring-boot-autoconfigure}/amqp/RabbitProperties.{sc-ext}[RabbitProperties])
|
||||
spring.rabbitmq.addresses= # Comma-separated list of addresses to which the client should connect.
|
||||
spring.rabbitmq.cache.channel.checkout-timeout= # Number of milliseconds to wait to obtain a channel if the cache size has been reached.
|
||||
|
||||
@@ -4082,7 +4082,7 @@ receive messages asynchronously. Spring AMQP provides a similar feature set for
|
||||
'`Advanced Message Queuing Protocol`' and Spring Boot also provides auto-configuration
|
||||
options for `RabbitTemplate` and RabbitMQ. There is also support for STOMP messaging
|
||||
natively in Spring WebSocket and Spring Boot has support for that through starters and a
|
||||
small amount of auto-configuration.
|
||||
small amount of auto-configuration. Spring Boot also has support for Apache Kafka.
|
||||
|
||||
|
||||
|
||||
@@ -4452,7 +4452,84 @@ throw an `AmqpRejectAndDontRequeueException` to signal the message should be rej
|
||||
This is the mechanism used when retries are enabled and the maximum delivery attempts are
|
||||
reached.
|
||||
|
||||
[[boot-features-kafka]]
|
||||
|
||||
=== Apache Kafka Support
|
||||
|
||||
http://kafka.apache.org/[Apache Kafa] is supported by providing auto-configuration of the `spring-kafka` project.
|
||||
|
||||
Kafka configuration is controlled by external configuration properties in `spring.kafka.*`. For example, you might
|
||||
declare the following section in `application.properties`:
|
||||
|
||||
[source,properties,indent=0]
|
||||
----
|
||||
spring.kafka.bootstrap-servers=localhost:9092
|
||||
spring.kafka.consumer.group-id=myGroup
|
||||
----
|
||||
|
||||
See {sc-spring-boot-autoconfigure}/kafka/KafkaProperties.{sc-ext}[`KafkaProperties`]
|
||||
for more of the supported options.
|
||||
|
||||
=== Sending a Message
|
||||
|
||||
Spring's `KafkaTemplate` is auto-configured and you can autowire them directly in your own beans:
|
||||
|
||||
[source,java,indent=0]
|
||||
----
|
||||
@Component
|
||||
public class MyBean {
|
||||
|
||||
private final KafkaTemplate kafkaTemplate;
|
||||
|
||||
@Autowired
|
||||
public MyBean(KafkaTemplate kafkaTemplate) {
|
||||
this.kafkaTemplate = kafkaTemplate;
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
}
|
||||
----
|
||||
|
||||
=== Receiving a Message
|
||||
|
||||
[source,java,indent=0]
|
||||
----
|
||||
@Component
|
||||
public class MyBean {
|
||||
|
||||
@KafkaListener(topics = "someTopic")
|
||||
public void processMessage(String content) {
|
||||
// ...
|
||||
}
|
||||
|
||||
}
|
||||
----
|
||||
|
||||
[[kafka-extra-props]]
|
||||
=== Additional Kafka Properties
|
||||
|
||||
The properties supported by auto configuration are shown in <<common-application-properties>>.
|
||||
Note that these properties (hyphenated or camelCase) map directly to the Apache Kafka dotted properties, refer
|
||||
to the Apache Kafka documentation for details.
|
||||
The first few of these properties apply to both producers and consumers, but can be specified at the producer or
|
||||
consumer level if you wish to use different values for each.
|
||||
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.
|
||||
Only a subset of the properties supported by Kafka are available via the `KafkaProperties` class.
|
||||
If you wish to configure the producer or consumer with additional properties, you can override the producer factory
|
||||
and/or consumer factory bean, adding additional properties, for example:
|
||||
|
||||
[source,java,indent=0]
|
||||
----
|
||||
@Bean
|
||||
public ProducerFactory<?, ?> kafkaProducerFactory(KafkaProperties properties) {
|
||||
Map<String, Object> producerProperties = properties.buildProducerProperties();
|
||||
producerProperties.put("some.property", "some.value");
|
||||
return new DefaultKafkaProducerFactory<Object, Object>(producerProperties);
|
||||
}
|
||||
----
|
||||
|
||||
[[boot-features-restclient]]
|
||||
== Calling REST services
|
||||
@@ -4514,8 +4591,6 @@ Lastly, the most extreme (and rarely used) option is to create your own
|
||||
`RestTemplateBuilder` bean. This will switch off the auto-configuration of a
|
||||
`RestTemplateBuilder` and will prevent any `RestTemplateCustomizer` beans from being used.
|
||||
|
||||
|
||||
|
||||
[[boot-features-email]]
|
||||
== Sending email
|
||||
The Spring Framework provides an easy abstraction for sending email using the
|
||||
|
||||
Reference in New Issue
Block a user