> For the complete documentation index, see [llms.txt](https://docs.scanner.dev/scanner/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.scanner.dev/scanner/using-scanner-complete-feature-reference/data-ingestion/sources/streams/kafka.md).

# Apache Kafka

Scanner can ingest data from self-managed Apache Kafka clusters. Rather than consuming from Kafka directly, Scanner reads from an S3 collect buffer bucket that a Kafka Connect S3 sink connector writes to. This lets you reuse the Kafka Connect infrastructure you likely already run, and keeps Scanner out of your consumer group management.

## Step 1: Set up the collect buffer bucket

Follow the [Streams overview](/scanner/using-scanner-complete-feature-reference/data-ingestion/sources/streams.md) to create an S3 collect buffer bucket with a 7-day lifecycle policy and link it to Scanner.

## Step 2: Run an S3 sink connector on Kafka Connect

We recommend the [Aiven S3 sink connector for Apache Kafka](https://github.com/Aiven-Open/cloud-storage-connectors-for-apache-kafka). It is Apache 2.0 licensed and can natively write newline-delimited JSON with gzip compression, which is exactly the format Scanner ingests most easily. Use the 3.x releases; the older 2.x line (`aiven/s3-connector-for-apache-kafka`) requires static AWS keys and cannot authenticate via IAM roles or instance profiles.

Example connector configuration:

```json
{
  "name": "scanner-collect-buffer-sink",
  "connector.class": "io.aiven.kafka.connect.s3.AivenKafkaConnectS3SinkConnector",
  "topics": "my-logs-topic",
  "aws.s3.bucket.name": "my-company-scanner-collect-buffer",
  "aws.s3.region": "us-east-1",
  "aws.s3.prefix": "kafka/my-logs-topic/{{ utc_date }}/",
  "format.output.type": "jsonl",
  "format.output.fields": "value",
  "format.output.envelope": "false",
  "file.compression.type": "gzip",
  "file.max.records": "10000",
  "key.converter": "org.apache.kafka.connect.storage.StringConverter",
  "value.converter": "org.apache.kafka.connect.json.JsonConverter",
  "value.converter.schemas.enable": "false",
  "errors.tolerance": "all",
  "errors.log.enable": "true"
}
```

Key settings:

* `format.output.type: jsonl` writes one JSON event per line (newline-delimited JSON).
* `format.output.fields: value` with `format.output.envelope: false` writes each record value as plain JSON. `format.output.envelope` defaults to `true`, which nests every event under a `{"value": ...}` wrapper.
* `file.compression.type: gzip` compresses each output file.
* `errors.tolerance: all` skips records that fail conversion (e.g. non-JSON messages) instead of permanently failing the connector task; `errors.log.enable: true` logs each skipped record.
* `aws.s3.prefix` supports `{{ utc_date }}` for date-partitioned keys; `file.name.template` offers finer control. See the [Aiven S3 sink documentation](https://aiven.io/docs/products/kafka/kafka-connect/reference/s3-sink-additional-parameters.html).
* AWS credentials come from the standard AWS credential chain (environment variables, instance profiles, etc.), or can be set with `aws.access.key.id` / `aws.secret.access.key`.

Files are flushed to S3 when `file.max.records` is reached or at the Connect offset flush interval (`offset.flush.interval.ms`, 60 seconds by default), so data lands in S3 within about a minute even on low-volume topics.

### Plaintext topics

If a topic carries plaintext log lines rather than JSON, `JsonConverter` would fail on every message, and `errors.tolerance: all` would skip them all (logged, but nothing ingested). Instead set:

```json
{
  "value.converter": "org.apache.kafka.connect.storage.StringConverter",
  "format.output.envelope": "true"
}
```

Each line is then written as `{"value": "<log line>"}`, still gzip JSONL, with the message text under the `value` field in Scanner.

### Alternative connectors

The `errors.tolerance` and converter guidance above is Kafka Connect framework-level and applies to these connectors too.

* [Confluent S3 Sink Connector](https://docs.confluent.io/kafka-connectors/s3-sink/current/overview.html): the most widely deployed S3 sink. Licensed under the Confluent Community License, which permits self-hosting for your own use. Use `format.class` of `io.confluent.connect.s3.format.json.JsonFormat` (writes one JSON record per line) with `s3.compression.type: gzip`, and set `value.converter.schemas.enable: false` to avoid wrapping each record in a `schema`/`payload` envelope. For low-volume topics, set `rotate.schedule.interval.ms` so files are flushed on wall-clock time rather than waiting for `flush.size` records to accumulate. For plaintext topics, use `io.confluent.connect.s3.format.bytearray.ByteArrayFormat` and ingest as `Plaintext` instead of `JsonLines`.
* [Lenses Stream Reactor AWS S3 sink](https://docs.lenses.io/latest/connectors/kafka-connectors/sinks/aws-s3): Apache 2.0 licensed, configured with SQL-like KCQL statements, e.g. `INSERT INTO my-bucket:prefix SELECT * FROM my-topic STOREAS 'JSON'`.

## Step 3: Ingest via Scanner Collect

Follow the [Create an Index Rule](/scanner/using-scanner-complete-feature-reference/data-ingestion/create-an-index-rule.md) guide to ingest the collect buffer bucket via Scanner Collect, using File Type `JsonLines` and Compression `Gzip`.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.scanner.dev/scanner/using-scanner-complete-feature-reference/data-ingestion/sources/streams/kafka.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
