Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I get producer client id in kafka consumer?

Tags:

apache-kafka

During creating kafka producer, we can assign a client id. What is it used for? Can I get the producer client id in a consumer? For example, to see which producer produced the message?

like image 307
Xiang Zhang Avatar asked Feb 02 '18 16:02

Xiang Zhang


People also ask

What is producer client ID in Kafka?

An optional identifier of a Kafka consumer (in a consumer group) that is passed to a Kafka broker with every request. The sole purpose of this is to be able to track the source of requests beyond just ip and port by allowing a logical application name to be included in Kafka logs and monitoring aggregates.

What is Groupid in Kafka consumer?

The consumer group ID is the unique identifier for the consumer group within the cluster. This is part of the consumer configuration for the application client. Active Members. Active members shows the number of consumers in the group that are assigned to a topic partition in the Kafka instance.

Does Kafka producer need Group ID?

The Kafka producer is conceptually much simpler than the consumer since it has no need for group coordination.

What is client ID in Apache Kafka?

The kafka documentation describes the clientId as: Client-id is a logical grouping of clients with a meaningful name chosen by the client application. The tuple (user, client-id) defines a secure logical group of clients that share both user principal and client-id.


2 Answers

No, a consumer cannot get the producer's client-id.

From the Kaka documentation, client-ids are:

An id string to pass to the server when making requests. The purpose of this is to be able to track the source of requests beyond just ip/port by allowing a logical application name to be included in server-side request logging.

They are only used for identifying clients in the broker logs.

like image 147
Mickael Maison Avatar answered Oct 02 '22 00:10

Mickael Maison


No, you'd have to pass it on as part of the key or value if you need it at the consumer side.

Kafka's philosophy is to decouple producers and consumers. A topic can be read by 0-n consumers and be written to by 0-n producers. Kafka is usually used for communication between (micro)service boundaries where services don't care about who produced a message, just about its contents.

like image 33
Ruurtjan Pul Avatar answered Oct 02 '22 00:10

Ruurtjan Pul