Apache Kafka has become the leading platform for asynchronous communication between microservices. It has powerful features that enable you to build fault- and fault-tolerant asynchronous architectures.
. , (, ) , , .
: . , , . , , , .
Kafka
, , Kafka. , Kafka , . .
,
Kafka β . Kafka :
(event log), .
(producers, publishers), .
(consumers), .
, RabbitMQ, Kafka , (.. Kafka pull, push ). (offset), ( ) . .
(topics), , . , , , :
- , .
- , .
(partitions). . Kafka (partition key). β ( , , ), .
UUID . (, UUID ), - .
, , , .
, . Kafka .
Kafka
Kafka . , . , .
, . (.. ), . - , .
, , , ..
, : ( ) . , : , .
(cross-boundary event publishing).
, (aggregates). β , . «» , , .
UserAccount. , , User ( ID: , , ..). , (EmailAddress, PhoneNumber ..). , ID ID.
UserAccount , (JSON Avro, ) UserAccount. , ID . UserAccount .
, ?
Kafka , . . , , , : .
?
, , . , β¦ , - .
, . , . : ?
(retry)?
, (.. ), . , ?
, . . , .
, ?
. , β β, UserAccount, . (, HTTP 400) .
, . , -, . , .
, . , . , , , .
, , .
?
. , , , , . : , .
Retry topic:
, , (retry topic). , :
- .
- , , .
- , , . . , .
- , ( (backoff strategy)). , , (dead letter queue, DLQ), .
retry-topic ( ) , . , , 1 , . , , . , , (dead letter queue, DLQ)
?
, . . , . , , .
: , : .
(recoverable errors) β , , , . , . , , . , .
- : , . , , . ( . «» , β β . , - β β .)
, . , . () . - , , ..
(non-recoverable errors) β , , , . , NullPointerException. - .
, , . , , , ..
, , , «» ( «» : !) , , NULLS , .
?
, . , , . , , . , , β¦ , .
? . , (, ).
, , . , β¦
. Kafka. , ID .
? , .
. ? , . , , , . .
. User , . Zoey Zo⦠Zoiee. , (, Login) Zoiee, Zo.
Login User. , Zoiee : Β« , Zo!Β»
retry topic. . , Zo, , . , Zoiee, , Zo.
Zoiee/Zo . . , . , - , . , , , .
retry topic ?
, . , , . , , β . :
- , - .
- , ( , .
- , .
.
. . . β , .. β .
. . , . , , . , , .
, 100% , :
- , , ,
- , .
?
, , , ?
, , , . , .
, . , , .
, :
void processMessage(KafkaMessage km) { try { Message m = km.getMessage(); transformAndSave(m); } catch (Throwable t) { if (isRecoverable(t)) { // ... } else { // ... } } }
- Java isRecoverable()
(whitelist approach) , t . , t, (, SQL REsT), true, . , false. .
, . , SQLException () (). , , , , stash topic ( -), β¦ , .
, . , . , .
, .
. . -Java - :
void processMessage(KafkaMessage km) { try { Message m = km.getMessage(); transformAndSave(m); } catch (Throwable t) { if (isRecoverable(t)) { doWithRetry(m, Backoff.EXPONENTIAL, this::transformAndSave); } else { // ... } } }
(, , , , ).
,
, , , , , . ? . n , DLQ. ?
, - , . DLQ, . .
, . User/Login. Login , Zo. , . Zoiee .
Zo , Zoiee . .
, , . Zo , .
Zo, . User Zoiee, Login Zo.
, . Zo Login Zoiee, . , .
ID , , ID. , β¦ .
, (: , !). . , -. . , ( , ), .
, , . , :
- , ;
- , .
, , -.
?
. , . , .
, ( β β) . , .
, , . . Kafka, . , β , β , .
, , , .
, . , , :
- , Kafka , .
- .
- , .
- Kafka , . ? . , ? .
- , .
:
, Apache Kafka, Stripe. . , .
:
- https://dzone.com/articles/creating-apache-kafka-topics-dynamically-as-part-o
- https://quarkus.io/blog/kafka-failure-strategy/
- https://eng.uber.com/reliable-reprocessing/
- https://jaceklaskowski.gitbooks.io/apache-kafka/content/kafka-topics.html
- https://www.red-gate.com/simple-talk/sql/bi/reconciling-data-across-systems-using-reconciliation-hub/