Posts Kafka Api
Post
Cancel

Kafka Api

Kafka API


๐Ÿ’ฟ Kafka API

image

Kafka API

  • Kafka Producer API: directly producing data
  • Kafka Connect Source API: bridging between a datastores we donโ€™t control and kafka
  • KafkaStreams API/KSQL: App wanting to consume from Kafka and produce back into Kafka, also called stream processing
    • Use KSQL can write your real time job as SQL-like
  • Kafka Consumer API: Read a stream and perfrom real-time action on it
  • Kafka Connect Sink API: Read a stream and store it into a target store
    • Kafa to S3, Kafka to HDFS, KafKa to (R)DBMS

๋ถ„๋ฅ˜

์œ„์˜ ๊ฒƒ๋“ค์„ ํฌ๊ฒŒ ๋‚˜๋ˆ„์ž๋ฉด 3๊ฐ€์ง€ ์ด๋‹ค.

  • Conntector ๊ณ„์—ด: ๋ถ„์‚ฐ ์ปค๋„ฅํŠธ๋ฅผ ๊ตฌ์ถ•ํ•ด์•ผํ•จ
    • Source & Sink API
    • connect-api ์‚ฌ์šฉ
  • Producer / Consumer ๊ณ„์—ด: ์ธํ”„๋ผ(๋ถ„์‚ฐ ์ปค๋„ฅํŠธ) ๊ตฌ์ถ• X
    • Producer & Consumer API
    • kafka-client ์‚ฌ์šฉ
    • spring kafka(์–ด๋“œ๋ฏผ, ์ปจ์Šˆ๋จธ, ํ”„๋กœ๋“€์„œ, ์ŠคํŠธ๋ฆผ์ฆˆ ์ œ๊ณต)
  • Stream ๊ณ„์—ด
    • Kfka Streams

๐Ÿ’ฟ Kafka Connector

ํŠน์ •ํ•œ ์ž‘์—… ํ˜•ํƒœ๋ฅผ ํ…œํ”Œ๋ฆฟ์œผ๋กœ ๋งŒ๋“ค์–ด ๋†“์€ ์ปค๋„ฅํ„ฐ๋ฅผ ์‹คํ–‰ํ•จ์œผ๋กœ์„œ ๋ฐ˜๋ณต ์ž‘์—…์„ ์ค„์ผ ์ˆ˜ ์žˆ๋‹ค.

๋ถ„๋ฅ˜

  • ์†Œ์Šค ์ปค๋„ฅํ„ฐ: ๋ฐ์ดํ„ฐ๋ฅผ ํ† ํ”ฝ์œผ๋กœ ์ „์†ก(ํ”„๋กœ๋“€์„œ ์—ญํ• )
  • ์‹ฑํฌ ์ปค๋„ฅํ„ฐ: ํ† ํ”ฝ์˜ ๋ฐ์ดํ„ฐ๋ฅผ ๋‹ค๋ฅธ ์ €์žฅ์†Œ์— ์ €์žฅ(์ปจ์Šˆ๋จธ ์—ญํ• )

๊ตฌ์„ฑ

image

  • ์‚ฌ์šฉ์ž๊ฐ€ ์ปค๋„ฅํŠธ์— ์ปค๋„ฅํ„ฐ ์ƒ์„ฑ ๋ช…๋ น์„ ๋‚ด๋ฆฌ๋ฉด ์ปค๋„ฅํŠธ๋Š” ๋‚ด๋ถ€์— ์ปค๋„ฅํ„ฐ์™€ ํƒœ์Šคํฌ๋ฅผ ์ƒ์„ฑ
    • ๋ณดํ†ต Task๋Š” ์‹ค์งˆ์ ์ธ ๋ฐ์ดํ„ฐ๋ฅผ ์ฒ˜๋ฆฌํ•˜๊ธฐ ๋•Œ๋ฌธ์— Customํ•˜์—ฌ ์‚ฌ์šฉ
  • ์ปค๋„ฅํ„ฐ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํŒŒ์ดํ”„๋ผ์ธ์„ ์ƒ์„ฑํ•  ๋•Œ converter ์™€ Trasform ๊ธฐ๋Šฅ์„ ์˜ต์…˜์œผ๋กœ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ๋‹ค.
    • ์ปจ๋ฒ„ํ„ฐ: ๋ฐ์ดํ„ฐ๋ฅผ ์ฒ˜๋ฆฌํ•˜๊ธฐ ์ „์— ์Šคํ‚ค๋งˆ๋ฅผ ๋ณ€๊ฒฝํ•˜๋„๋ก ๋„์™€์ค€๋‹ค.
      • JsonConverter, StringConverter, ByteConverter๋ฅผ ์ง€์›
      • ์•„๋‹ˆ๋ฉด ์ง์ ‘ CustomConver๋ฅผ ์ž‘์„ฑ ๊ฐ€๋Šฅ
    • Tramsform: ๋ฐ์ดํ„ฐ ์ฒ˜๋ฆฌ ์‹œ ๊ฐ ๋ฉ”์‹œ์ง€ ๋‹จ์œ„๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ„๋‹จํ•˜๊ฒŒ ๋ณ€ํ™˜ํ•˜๊ธฐ ์œ„ํ•œ ์šฉ๋„
      • Json ๋ฐ์ดํ„ฐ๋ฅผ ์ปค๋„ฅํ„ฐ์—์„œ ์‚ฌ์šฉํ• ๋•Œ ํŠน์ • ํ‚ค๋ฅผ ์‚ญ์ œํ•˜๊ฑฐ๋‚˜ ์ถ”๊ฐ€ ๊ฐ€๋Šฅ
      • Cast, Drop, ExtractField ๋“ฑ์ด ๊ธฐ๋ณธ์ ์œผ๋กœ ์ œ๊ณต

๐Ÿ’ฟ Kafka Connector ์‹คํ–‰

๋‹จ์ผ ๋ชจ๋“œ

ํ•˜๋‚˜์˜ ํ”„๋กœ์„ธ์Šค์— 1ํ•˜๋‚˜์˜ ์ปค๋„ฅํŠธ๊ฐ€ ์‹คํ–‰๋˜์–ด ๊ทธ๋ฃน์˜ ๊ฐœ๋… ์—†์ด ํ˜ผ์ž ๋ชจ๋“  ๋ฐ์ดํ„ฐ๋ฅผ ์ฒ˜๋ฆฌ

๋ถ„์‚ฐ ๋ชจ๋“œ

2๊ฐœ ์ด์ƒ์˜ ํ”„๋กœ์„ธ์Šค๊ฐ€ 1๊ฐœ์˜ ๊ทธ๋ฃน์œผ๋กœ ๋ฌถ์—ฌ์„œ ์šด์˜

  • 1๊ฐœ์˜ ์ปค๋„ฅํŠธ ํ”„๋กœ์„ธ์Šค์— ์ด์Šˆ๊ฐ€ ๋ฐœ์ƒํ•˜์—ฌ ์ข…๋ฃŒ๋˜๋”๋ผ๋„ ์‚ด์•„์žˆ๋Š” ๋‚˜๋จธ์ง€ 1๊ฐœ ์ปค๋„ฅํŠธ ํ”„๋กœ์„ธ์Šค๊ฐ€ ์ปค๋„ฅํ„ฐ๋ฅผ ์ด์–ด๋ฐ›์•„์„œ ํŒŒ์ดํ”„๋ผ์ธ์„ ์ง€์†์ ์œผ๋กœ ์‹คํ–‰

__

๐Ÿ’ฟ ์žฅ์  ๊ณผ ๋‹จ์ 

Kafka Producer(Consumer) API

  • ์žฅ์ 
    • Extremely simple to use
    • multithread๋กœ ๊ตฌ์„ฑ ๊ฐ€๋Šฅ
    • ๋ถ„์‚ฐ ์ปค๋„ฅํŠธ ๊ตฌ์ถ• ํ•„์š” ์—†์Œ
    • perfectly suited for applications directly emitting stream of data such as logs, clickstreams, IOT
  • ๋‹จ์ 
    • Producer API can be extended and built upon to do a lot more thing
    • this will requre engineers to write a lot of added logic
    • How to track the source offset(how to resume if stopped)
    • How to distribute the load for your ETL(converter, transformer) across many producers

Connect Source(Sink) Connect API

  • ์žฅ์ 
    • built so that developers would get a nicer API made for
      • producer tasks distribution for parallel processing
      • easy mechanism to resume your producers
      • ํƒœ์Šคํฌ ๋งˆ๋‹ค ๋‹ค๋ฅด config ๊ฐ€๋Šฅ
    • bustiling variety of available connectors
  • ๋‹จ์ 
    • ๋ถ„์‚ฐ ์ปค๋„ฅํŠธ๋ฅผ ์ง์ ‘ ๊ตฌ์„ฑํ•ด์•ผ ํ•จ
    • ๋‹จ์ ์„ ์ž˜ ๋ชจ๋ฅด๊ฒ ์Œ
This post is licensed under CC BY 4.0 by the author.

Apache Kafka 2

Programming Skills 1