问题
I have a classic microservice architecture. So, there are differ applications. Each application may have 1..N
instances. The system is deployed to Kubernetes.
So, we have many differ PODs
, which can start and stop in any time.
I want to implement read-process-write pattern, so I need Kafka transactions.
To configure transactions, I need to set some transaction id
for each Kafka producer. (Actually, I need transaction-id-prefix
, because of I use Spring for my applications, and it has such API
). These IDs
have to be the same, after application is restarted.
So, how to choose Kafka transaction id for several applications, hosted in Kubernetes?
回答1:
If the consumer starts the transaction (read-process-write) then the transaction id prefix must be the same for all instances of the same app (so that zombie fencing works correctly after a rebalance). The actual transaction id used is <prefix><group>.<topic>.<partition>
.
If you have multiple apps, they should have unique prefixes (although if they consume from different topics, they will be unique anyway).
For producer-only transactions, the prefix must be unique in each instance (to prevent kafka fencing the producers).
来源:https://stackoverflow.com/questions/57179169/how-to-choose-kafka-transaction-id-for-several-applications-hosted-in-kubernete