日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

kakfa 入门

發布時間:2023/12/29 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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

總結

以上是生活随笔為你收集整理的kakfa 入门的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。