Flume (十) Sources - Kafka Source

Kafka Source是一個Apache Kafka消費者,它從Kafka主題中讀取消息。 如果您正在運行多個Kafka Source,可以爲這些Source配置相同的消費者組(Consumer Group),以便每個Source都讀取一組唯一的主題分區。

屬性名稱 默認值 描述
channels
type 組件類型名稱,需要是org.apache.flume.source.kafka.KafkaSource
kafka.bootstrap.servers source使用的Kafka集羣中的代理列表
kafka.consumer.group.id flume consumer group 唯一標識. 在多個源或代理中設置相同的ID表示它們是同一個consumer group的一部分
kafka.topics 以逗號分隔的主題列表,kafka消費者將從中讀取消息。
kafka.topics.regex 正則表達式,用於定義源訂閱的主題集。 此屬性具有比kafka.topics更高的優先級,並覆蓋kafka.topics(如果存在)
batchSize 1000 一批中寫入Channel的最大消息數
batchDurationMillis 1000 Maximum time (in ms) before a batch will be written to Channel The batch will be written whenever the first of size and time will be reached.
backoffSleepIncrement 1000 Initial and incremental wait time that is triggered when a Kafka Topic appears to be empty. Wait period will reduce aggressive pinging of an empty Kafka Topic. One second is ideal for ingestion use cases but a lower value may be required for low latency operations with interceptors.
maxBackoffSleep 5000 Kafka主題出現爲空時觸發的最長等待時間。 5秒是攝取用例的理想選擇,但使用攔截器的低延遲操作可能需要較低的值。
useFlumeEventFormat false 默認情況下,事件從Kafka主題直接作爲字節直接進入事件主體。 設置爲true以將事件讀取爲Flume Avro二進制格式。 與KafkaSink上的相同屬性或Kafka Channel上的parseAsFlumeEvent屬性一起使用時,這將保留在生成端發送的任何Flume標頭。
setTopicHeader true 設置爲true時,將檢索到的消息的主題存儲到由topicHeader屬性定義的標頭中。
topicHeader topic 如果setTopicHeader屬性設置爲true,則定義用於存儲接收消息主題名稱的標頭名稱。 如果與Kafka Sink topicHeader屬性結合使用,應該小心,以避免將消息發送回循環中的同一主題。
migrateZookeeperOffsets true 如果找不到Kafka存儲的偏移量,請在Zookeeper中查找偏移量並將它們提交給Kafka。 這應該是支持從舊版本的Flume無縫Kafka客戶端遷移。 遷移後,可以將其設置爲false,但通常不需要這樣做。 如果未找到Zookeeper偏移量,則Kafka配置kafka.consumer.auto.offset.reset定義如何處理偏移量。 有關詳細信息,請查看Kafka文檔
kafka.consumer.security.protocol PLAINTEXT 如果使用某種級別的安全性寫入Kafka,則設置爲SASL_PLAINTEXTSASL_SSLSSL。 有關安全設置的其他信息,請參見下文。
more consumer security props 如果使用SASL_PLAINTEXT,則SASL_SSLSSL會引用Kafka安全性以獲取需要在使用者上設置的其他屬性。
Other Kafka Consumer Properties 這些屬性用於配置Kafka Consumer。 可以使用Kafka支持的任何consumer property。 唯一的要求是使用前綴kafka.consumer添加屬性名稱。 例如:kafka.consumer.auto.offset.reset

Note
Kafka Source覆蓋兩個Kafka consumer 參數:source auto.commit.enable設置爲“false”,並且每個批處理都已提交。 Kafka source 保證至少一次消息檢索策略。 source啓動時可以存在重複項。 Kafka Source還提供了key.deserializer(org.apache.kafka.common.serialization.StringSerializer)和value.deserializer(org.apache.kafka.common.serialization.ByteArraySerializer)的默認值。 不建議修改這些參數。

不推薦使用的屬性

Property Name Default Description
topic Use kafka.topics
groupId flume Use kafka.consumer.group.id
zookeeperConnect 自0.9.x以來,kafka消費者客戶不再支持。使用kafka.bootstrap.servers與kafka集羣建立連接

通過逗號分隔的主題列表進行主題訂閱的示例。

tier1.sources.source1.type = org.apache.flume.source.kafka.KafkaSource
tier1.sources.source1.channels = channel1
tier1.sources.source1.batchSize = 5000
tier1.sources.source1.batchDurationMillis = 2000
tier1.sources.source1.kafka.bootstrap.servers = localhost:9092
tier1.sources.source1.kafka.topics = test1, test2
tier1.sources.source1.kafka.consumer.group.id = custom.g.id

正則表達式主題訂閱的示例

tier1.sources.source1.type = org.apache.flume.source.kafka.KafkaSource
tier1.sources.source1.channels = channel1
tier1.sources.source1.kafka.bootstrap.servers = localhost:9092
tier1.sources.source1.kafka.topics.regex = ^topic[0-9]$
# the default kafka.consumer.group.id=flume is used

Security and Kafka Source:
Flume和Kafka之間的通信渠道支持安全認證和數據加密。 對於安全身份驗證,可以使用Kafka 0.9.0版中的SASL / GSSAPI(Kerberos V5)或SSL(即使該參數名爲SSL,實際協議是TLS實現)。

截至目前,數據加密僅由SSL / TLS提供。

kafka.consumer.security.protocol設置爲以下任意值意味着:
- SASL_PLAINTEXT - 沒有數據加密的Kerberos或純文本身份驗證
- SASL_SSL - 使用數據加密的Kerberos或純文本身份驗證
- SSL - 基於TLS的加密和可選的身份驗證。

警告:啓用SSL時性能會下降,其大小取決於CPU類型和JVM實現。 Reference: Kafka security overview and the jira for tracking this issue: KAFKA-2561

TLS and Kafka Source:
請閱讀配置Kafka客戶端SSL中描述的步驟,以瞭解用於微調的其他配置設置,例如以下任何一項:安全提供程序,密碼套件,啓用的協議,信任庫或密鑰庫類型。

配置服務器端身份驗證和數據加密的示例。

a1.sources.source1.type = org.apache.flume.source.kafka.KafkaSource
a1.sources.source1.kafka.bootstrap.servers = kafka-1:9093,kafka-2:9093,kafka-3:9093
a1.sources.source1.kafka.topics = mytopic
a1.sources.source1.kafka.consumer.group.id = flume-consumer
a1.sources.source1.kafka.consumer.security.protocol = SSL
a1.sources.source1.kafka.consumer.ssl.truststore.location=/path/to/truststore.jks
a1.sources.source1.kafka.consumer.ssl.truststore.password=<password to access the truststore>

注意:默認情況下,未定義屬性ssl.endpoint.identification.algorithm,因此不會執行主機名驗證。 要啓用主機名驗證,請設置以下屬性

a1.sources.source1.kafka.consumer.ssl.endpoint.identification.algorithm=HTTPS

啓用後,客戶端將根據以下兩個字段之一驗證服務器的完全限定域名(FQDN):

如果還需要客戶端身份驗證,則還應將以下內容添加到Flume代理配置中。 每個Flume代理都必須擁有其客戶證書,該證書必須由Kafka brokers 單獨或通過其簽名鏈進行信任。 常見示例是由單個根CA簽署每個客戶端證書,而後者又由Kafka代理信任。

a1.sources.source1.kafka.consumer.ssl.keystore.location=/path/to/client.keystore.jks
a1.sources.source1.kafka.consumer.ssl.keystore.password=<password to access the keystore>

如果密鑰庫和密鑰使用不同的密碼保護,則ssl.key.password屬性將爲兩個使用者密鑰庫提供所需的額外密鑰:

a1.sources.source1.kafka.consumer.ssl.key.password=<password to access the key>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章