liveBook · Manning

Kafka producer

As explained in Kafka Streams in Action, Second Edition

KafkaProducer is the Kafka client API class that publishes records to Kafka topics.

A Kafka producer publishes records to Kafka topics. It sends records to brokers, which store them for independent consumers. This client is the entry point for getting application data into an event-streaming system. section 1.4.3 section 4.1

KafkaProducer receives configuration properties and creates ProducerRecord objects containing the topic, key, and value. Calling send() is asynchronous: the producer batches records and sends them when its buffer is full or the send time arrives. section 4.2

A practical producer flow is:

  • Fetch or generate application records, such as point-of-sale transactions. section 4.2
  • Map each domain object into a ProducerRecord with a topic, key, and value. section 4.2
  • Pass each record to KafkaProducer.send() and handle callback metadata or exceptions. section 4.2
  • Use schemas and compatible serializers when producers and consumers share structured domain data. section 3.9

Publishing sales transactions

A wholesale company receives transaction data containing product, price, quantity, timestamp, and customer fields. A Java producer turns each ProductTransaction into a ProducerRecord keyed by customer name, sends it asynchronously, and logs either the resulting offset and timestamp or the production error. section 4.2

Figure 1.6 Producers write records into Kafka, and consumers read records.
figure

Use the producer-consumer flow diagram to distinguish producers writing records into Kafka from consumers reading them. section 1.4.3

How Kafka Streams in Action, Second Edition covers it

How deep it goes
Explains configuration, record construction, asynchronous sending, batching, callbacks, and schema integration, then defers advanced delivery semantics.
Examples
Uses a wholesale sales-ingest pipeline, generated ProductTransaction objects, customer keys, callbacks, offsets, and timestamps.
What it assumes
Assumes basic Kafka event-streaming context while establishing producer, consumer, broker, topic, and schema roles.
What you can do after
Builds a Java producer that converts domain objects into records, sends them asynchronously, and handles delivery results.
How it connects
Connects KafkaProducer with brokers, topics, partitions, consumers, ProducerRecord, serializers, schemas, and Schema Registry.

Also explained in

Compare how 2 books explain Kafka producer →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kafka Streams in Action, Second Edition. The section links point to the parts of the book it draws on.