Spooldir CSV: Drop a File, Get Kafka JSON
A local Docker demo where Kafka Connect Spooldir watches a folder, turns each CSV row into JSON, and publishes it on the employee-data topic.
Overview
You copy a CSV into a folder. A short wait later, every row is a JSON message on a Kafka topic, and the file itself has been moved out of the way.
That folder is a mailroom inbox. Kafka Connect’s Spooldir CSV Source Connector is the clerk: new file in, one message per row out, file filed under finished or error. This demo runs the whole clerk locally in Docker, so you can watch it with Kafka UI on localhost:8080.
The walkthrough lives in csv-spooldir-connector inside the kafkaDemos repo. The sibling demo reads the same kind of CSV from Azure Blob Storage: Azure Blob CSV.
How it works
./start-demo.sh brings the stack up, waits until Connect answers on port
8083, POSTs connector-config.json, and copies sample_data.csv into
data/input/ under a timestamped name. You can do the same steps by hand
with docker-compose up -d and a curl POST of that config.
data/input/*.csv
|
v
Spooldir CSV Source (Connect)
|
+---> [employee-data] ---> Kafka UI :8080
|
+-- ok ---> data/finished/
+-- error --> data/error/
- One topic.
topicisemployee-data. - Header row.
csv.first.row.as.headeris true, soID,Name,Department, andSalarybecome the JSON fields. - Plain JSON. Key and value converters are
JsonConverterwith schemas disabled. - One task.
tasks.maxis 1. The file pattern is.*\.csv.
A row from sample_data.csv shows up like this:
{
"ID": 1,
"Name": "Alice Smith",
"Department": "Engineering",
"Salary": 85000
}
What it demonstrates
- KRaft, single node. Kafka 7.7.1 runs as broker and controller. No ZooKeeper.
- Plugin install at start. The Connect container runs
confluent-hub install jcustenborder/kafka-connect-spooldir:2.0.65before it starts the worker. - A file lifecycle you can see.
./datais bind-mounted to/data. Input, finished, and error are directories on your disk. - Two ways to read the topic. Kafka UI (Topics, then employee-data), or
kafka-console-consumerinside thekafkacontainer.
Technical details
- Images:
confluentinc/cp-kafka:7.7.1,confluentinc/cp-kafka-connect:7.7.1,provectuslabs/kafka-ui. - Connector class:
com.github.jcustenborder.kafka.connect.spooldir.SpoolDirCsvSourceConnector. - Paths:
input.path/data/input,finished.path/data/finished,error.path/data/error. - Schema generation is enabled. The sample output above keeps
IDandSalaryas numbers. - Ports: broker
9092, Connect REST8083, Kafka UI8080.
Check status, or remove the connector:
curl http://localhost:8083/connectors/csv-spooldir-connector/status | jq
curl -X DELETE http://localhost:8083/connectors/csv-spooldir-connector
Challenges & lessons
- Wait for Connect, then POST. The container installs the Spooldir plugin
before it listens.
start-demo.shpollshttp://localhost:8083/for that reason. A POST in the first few seconds lands on nothing. - Processed files leave
data/input/. A good file moves underdata/finished/. A bad file moves underdata/error/. To see another batch, drop another CSV. The start script uses a timestamp in the filename so a second run does not collide with a file still sitting in input. - Connect’s internal topics are replication factor 1. This is a
single-broker KRaft node (
process.roles=broker,controller). Configs, offsets, and status use that factor on purpose. - The sample JSON is typed. With schema generation on, the README’s
expected record has numeric
IDandSalary. The Azure Blob demo publishes the same columns as strings.