Zuriar
Zuriar

Reputation: 11774

What ways can a Consumer consume message in Kafka?

If there is a Kafka server "over there" somewhere across the network I would assume that there might be two ways that a Consumer could consume the messages:

  1. By first of all 'subscribing' to the Topic and in effect telling the Kafka server where it is listening so that when a new message is Produced, Kafka proactively sends the message to the Consumer, across the network.

  2. The Consumer has to poll the Kafka server asking for any new messages, using the offset of the messages it has currently taken.

Is this how Kafka works, and is the option configurable for which one to use?

Upvotes: 5

Views: 8861

Answers (1)

Morgan Kenyon
Morgan Kenyon

Reputation: 3172

I'm expanding my comment into an answer.

Reading through the consumer documentation, Kafka only supports option 2 as you've described it. It is the consumers responsibility to get messages from the Kafka server. In the 0.9.x.x Consumer this is accomplished by the poll() method. The Consumer polls the Kafka Server and returns messages if there are any. There are several reasons I believe they've chosen to avoid supporting option 1.

  1. It limits the complexity needed in the Kafka Server. It's not the Server's responsibility to push messages to a consumer, it just holds the messages and waits till a consumer fetches them.
  2. If the Kafka Server was pushing all messages to the consumers, it could overwhelm a consumer. Say a Producer was pushing messaging into a Kafka Server 10 msg/sec, but a certain Consumer could only process 2 msg/sec. If the Kafka Server attempted to push every message it received to that Consumer, the Consumer would quickly be overwhelmed by the number of messages it receives.

There's probably other reasons, but at the moment those were the two I thought about.

Upvotes: 3

Related Questions