# Kafka task

A Kafka task writes a message to a topic of a Kafka cluster. Kafka is where many organisations collect events from all their systems; with this task a job adds its own: "this file arrived", "this delivery is complete".

The task sends. It does not read from Kafka. For other message brokers, see [JMS](Task-JMS.md) and [Message queues](Jobs-Messaging.md).

## Fields

### Connection

| Field | What it does | On a new task |
|---|---|---|
| **Host**, **Port** | a broker of the cluster | |
| **Username**, **Password** | for clusters that ask for them | |
| **SSL** | the connection is encrypted | on |
| **Keystore**, **Keystore Password** | this server's certificate, "only when SSL client authentication is required" | |
| **Truststore**, **Truststore Password** | the certificates this server shall trust, where the cluster's own are not signed by a known authority | |
| **Test Settings** | connects with what is in the form | |

For anything the fields do not cover:

| Field | What it does |
|---|---|
| **Load custom client config** | the task uses the lines of **Custom config** as its settings |
| **Custom config** | Kafka's own client settings, one `name=value` per line: `bootstrap.servers`, `security.protocol`, `sasl.mechanism`, `acks` and the rest |

### The message

| Field | What it does | On a new task |
|---|---|---|
| **Topic name** | the topic to write to | `test` |
| **Custom Topic** | the topic name may hold [variables](Jobs-Variables.md), so that it is worked out per item: `files.{user_name}` | off |
| **Key** | the message's key. Messages with the same key keep their order in Kafka. Often the file's name or the partner's. | |
| **Message** | the text, with variables | |

The task sends **one message per item** its filter matches. With **Process first item only**, one.

## A message

```
{"event":"file.received","name":"{name}","size":{size},"from":"{user_name}","at":"{yyyy}-{MM}-{dd}T{HH}:{mm}:{ss}"}
```

with the key `{user_name}`: everything about one partner stays in order.

## What it hands on

The items it was given, unchanged.

## Things to know

- **Files the server needs.** The Kafka client is not part of CrushMFT: its jar files go into `plugins/lib`, and the server is restarted once. See [Files the server needs](Jobs-Messaging.md#files-the-server-needs).
- **In the log**, the task lists the settings it uses, "Kafka Config -> …". Check there first when it does not connect.
- **Kafka is for telling.** Send the fact that a file arrived, not the file.
- **Many brokers.** One host is enough to find the others. To name several, use the custom config with `bootstrap.servers=a:9093,b:9093`.
- **Full administrators only**, in the older scheme of admin flags: a client config can name program code to load, so the task is taken out of a job that a limited admin saves. See [Who may see, change and run a job](Jobs-Access.md).
