kakfa 入门
?
springboot官網
Apache Kafka?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 。 ??
通過提供spring-kafka項目的自動配置支持Apache ,Kafka配置由spring.kafka中的外部配置屬性控制。 例如,您可以聲明以下部分:
spring.kafka.bootstrap-servers=localhost:9092
spring.kafka.consumer.group-id=myGroup
Spring’s?KafkaTemplate?is auto-configured and you can autowire them directly in your own beans:
Spring的KafkaTemplate是自動配置的,您可以直接在自己的bean中自動連接:
@Component public class MyBean {private final KafkaTemplate kafkaTemplate; @Autowired public MyBean(KafkaTemplate kafkaTemplate) { this.kafkaTemplate = kafkaTemplate; } // ... }When the Apache Kafka infrastructure is present, any bean can be annotated with?@KafkaListener?to create a listener endpoint. If no? KafkaListenerContainerFactory?has been defined,
a default one is configured automatically with keys defined in?spring.kafka.listener.*.
?當Apache Kafka存在時,任何bean都可以用@KafkaListener注釋來創建一個偵聽器端點。 如果沒有定義KafkaListenerContainerFactory,
?使用spring.kafka.listener中定義的鍵自動配置默認值。
The following component creates a listener endpoint on the?someTopic?topic:
以下組件在someTopic主題上創建一個偵聽器端點:@Componentpublic class MyBean {
@KafkaListener(topics = "someTopic")public void processMessage(String content) { // ... } }The properties supported by auto configuration are shown in?Appendix?A,?Common application properties. Note that these properties
(hyphenated or camelCase) map directly to the Apache Kafka dotted properties for the most part, 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 that are not directly supported, use the following: 自動配置支持的屬性如附錄A,常用應用程序屬性所示。 請注意,這些屬性(連字符或camelCase)大部分地直接映射到Apache Kafka虛線屬性,有關詳細信息,請參閱Apache Kafka文檔。這些屬性中的前幾個適用于生產者和消費者,
但如果您希望使用不同的產品,則可以在生產者或消費者層面進行指定每個值。 Apache Kafka指定具有重要性的屬性:HIGH,MEDIUM和LOW。 Spring Boot自動配置支持所有HIGH重要性,?一些選擇MEDIUM和LOW,任何沒有默認值只有Kafka
支持的屬性的一小部分可通過KafkaProperties類獲得。 如果您希望使用不直接支持的其他屬性來配置生產者或消費者,請使用以下內容:spring.kafka.properties.foo.bar=baz spring.kafka.consumer.properties.fiz.buz=qux spring,kafka.producer.properties.baz.qux=fiz
啟動kafka-server:PS E:\工作軟件及資料\軟件工作空間\kafka_2.12-0.11.0.1\bin\windows> ./kafka-server-start.bat ..\..\config\server.properties
創建topic : E:\工作軟件及資料\軟件工作空間\kafka_2.12-0.11.0.1\bin\windows> ./kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 3 --topic test1
Created topic "test1".
啟動生產者控制臺窗口:E:\工作軟件及資料\軟件工作空間\kafka_2.12-0.11.0.1\bin\windows> ./kafka-console-producer.bat --broker-list localhost:9092 --topic test1啟動消費者控制臺窗口:?E:\工作軟件及資料\軟件工作空間\kafka_2.12-0.11.0.1\bin\windows> ./kafka-console-consumer.bat --zookeeper localhost:2181 --from-beginning --topic test1 ?
?
? ? ?轉載于:https://www.cnblogs.com/liduanwen/p/7533094.html
總結
- 上一篇: simditor上传图片php,Simd
- 下一篇: 华为LAB实验室5—花卉分类