ConsumeKafka 2026.11.12.16

Bundle

org.apache.nifi | nifi-kafka-nar

Description

Reads messages from Apache Kafka topics and writes them to FlowFiles as raw content, delimited batches, or structured records.

The Processing Strategy determines how consumed messages are written:

  • FLOW_FILE (default) writes each Kafka message value to a separate FlowFile without parsing it.
  • DEMARCATOR combines messages from the same topic and partition, placing the UTF-8 Message Demarcator between values. If Separate By Key is true, messages with different keys are placed in different FlowFiles.
  • RECORD parses message values with the configured Record Reader and serializes them with the configured Record Writer. Records are grouped by topic, partition, and selected header values. Schema Conflict Resolution controls how records with conflicting schemas are grouped.

If a message can’t be parsed or written with the configured Record Reader or Record Writer, its contents are written to a separate FlowFile and transferred to the parse.failure relationship. Otherwise, FlowFiles are transferred to success and can contain multiple messages. The record.count attribute indicates the number of messages in a FlowFile.

Kafka header values selected for output use Header Format. They can be represented as text decoded with Header Encoding or as lowercase hexadecimal strings.

Tags

Consume, Get, Ingest, Ingress, Kafka, PubSub, Record, Topic, avro, csv, json

Input requirement

FORBIDDEN

Supports sensitive dynamic properties

false

Properties

Configure how the processor connects to Kafka, selects messages, and writes FlowFile content and attributes.

PropertyDescriptionConfiguration
Auto Offset ResetSets auto.offset.reset when the consumer group has no committed offset.Required. Values: earliest, latest (default), none. Expression Language isn’t supported.
Commit OffsetsControls whether the processor commits offsets after receiving messages.Required. Values: true (default), false.
Group IDSets the Kafka consumer group identifier that corresponds to group.id.Required. Expression Language isn’t supported.
Header EncodingCharacter set used to decode Kafka header values.Required when Header Format is string. Default: UTF-8.
Header FormatControls how Kafka header values are represented in attributes or record fields.Required. Values: string (default), hex.
Header Name PatternJava regular expression that selects Kafka headers for FlowFile attributes.Optional.
Header Name PrefixPrefix applied to attribute names created from Kafka headers to avoid reserved-name conflicts.Optional. Applies when Processing Strategy is FLOW_FILE.
Kafka Connection ServiceKafkaConnectionService controller service that supplies connections to Kafka brokers.Required. Expression Language isn’t supported.
Key Attribute EncodingControls how the Kafka key is written to the kafka.key attribute.Required. Values: utf-8 (default), hex, do-not-add.
Key FormatControls how wrapper output represents the Kafka record key.Required when Output Strategy is USE_WRAPPER or INJECT_METADATA. Values: string, byte-array (default), record.
Key Record ReaderRecordReaderFactory controller service used to parse Kafka record keys.Required when Key Format is record. Expression Language isn’t supported.
Max Uncommitted SizeMaximum combined size of serialized keys and values to consume before transferring FlowFiles.Optional. Evaluated before Max Uncommitted Time.
Max Uncommitted TimeMaximum time to consume records before transferring FlowFiles. Longer periods can produce larger FlowFiles and increase latency.Required. Default: 100 millis.
Message DemarcatorUTF-8 string inserted between Kafka messages combined in one FlowFile.Required when Processing Strategy is DEMARCATOR.
Output StrategyControls the representation of Kafka records in record-oriented FlowFiles.Required when Processing Strategy is RECORD. Values: USE_VALUE (default), USE_WRAPPER, INJECT_METADATA, INJECT_OFFSET.
Processing StrategyControls whether output uses individual FlowFiles, demarcated batches, or records.Required. Values: FLOW_FILE (default), DEMARCATOR, RECORD. Expression Language isn’t supported.
Record ReaderRecordReaderFactory controller service used to parse Kafka message values.Required when Processing Strategy is RECORD.
Record WriterRecordSetWriterFactory controller service used to serialize outgoing FlowFiles.Required when Processing Strategy is RECORD.
Schema Conflict ResolutionControls how records with different schemas are grouped into FlowFiles.Required when Processing Strategy is RECORD. Values: CREATE_NEW_FLOWFILE (default), CONTINUE_WITH_MERGED_SCHEMA.
Separate By KeyControls whether a demarcated FlowFile can contain messages with different keys.Required when Message Demarcator is configured. Values: true, false (default).
Topic FormatSpecifies whether Topics contains names or a Java regular expression.Required. Values: names (default), pattern.
TopicsIdentifies topics by a name, comma-separated names, or a pattern, depending on Topic Format.Required. Supports JVM environment variables and system properties.

The processor doesn’t support dynamic properties.

Output strategies

The Output Strategy property applies when Processing Strategy is RECORD:

  • Use Content as Value writes only the Kafka record value.
  • Use Wrapper writes the key, value, headers, and metadata as separate fields. The metadata contains the topic, partition, offset, and timestamp.
  • Inject Metadata writes the record value and adds a kafkaMetadata sub-record containing the topic, partition, offset, timestamp, headers, and key.
  • Inject Offset writes the record value and adds the Kafka offset.

When Output Strategy is Use Wrapper or Inject Metadata, Key Format specifies whether the Kafka record key is represented as a byte array, a UTF-8 string, or a record parsed by Key Record Reader. A key that can’t be parsed with the selected format is transferred to parse.failure.

Relationships

Connect this relationship to route FlowFiles after the processor consumes and serializes Kafka messages.

NameDescription
successRoutes FlowFiles that contain one or more serialized Kafka records.

Writes attributes

The processor writes these attributes to describe the Kafka messages in each output FlowFile.

NameDescription
record.countNumber of records written to the FlowFile.
mime.typeMIME type supplied by the configured Record Writer.
kafka.countNumber of Kafka messages represented by the FlowFile.
kafka.keyKey of a single Kafka message, when present. Key Attribute Encoding controls its encoding.
kafka.offsetOffset of a single Kafka message, or the lowest offset in a batch.
kafka.timestampTimestamp of a single Kafka message, or the earliest timestamp in a batch. The Kafka broker log.message.timestamp.type setting determines its meaning.
kafka.partitionPartition that supplied the message or batch.
kafka.topicTopic that supplied the message or batch.
kafka.max.offsetHighest Kafka offset in a batch.
kafka.tombstoneSet to true when the consumed message is a tombstone message.

See also