# Kafka Consumer

## Connection

Connect to your Kafka bootstrap broker(s):

```sh
ilagent daemon --kafka_brokers localhost:9092 --kafka_group_id ilagent \
    -e 'events-topic' -r 'heartbeats-topic'
```

| Flag               | Description                            | Default |
| ------------------ | -------------------------------------- | ------- |
| `--kafka_brokers`  | Comma-separated broker list (required) | —       |
| `--kafka_group_id` | Consumer group ID (required)           | —       |
| `-e`               | Topic for event messages               | —       |
| `-r`               | Topic for heartbeat messages           | —       |

## At least once delivery

In Kafka mode, events are **not** buffered in SQLite. Instead, the consumer offset is used to guarantee at least once delivery. If an event cannot be delivered, the offset is not committed and ilagent will exit after 5 seconds.

We recommend running ilagent so it is automatically restarted on exit:

```sh
docker run --restart always ilert/ilagent daemon \
    --kafka_brokers localhost:9092 --kafka_group_id ilagent \
    -e 'events-topic'
```

## Payload format

All message payloads must be JSON. An example event payload using the default field names:

```json
{
  "integrationKey": "il1api123...",
  "eventType": "ALERT",
  "summary": "Hey from Kafka"
}
```

If your payloads use different field names, you can map them with `--map_key_etype`, `--map_key_summary`, `--map_key_alert_key`, and set a fixed integration key with `--event_key`. See [Event Mapping](https://docs.ilert.com/developer-docs/client-libraries/ilagent/event-mapping) for details.

{% hint style="warning" %}
The `integrationKey` (or `--event_key`) must belong to a [**Kafka** alert source](https://github.com/iLert/docs/blob/master/product-docs/integrations/inbound-integrations/kafka.md) in ilert. Events sent with integration keys from other alert source types will be rejected.
{% endhint %}

An example heartbeat payload:

```json
{
  "integrationKey": "il1hbt123..."
}
```

## Sample command

```sh
ilagent daemon -v -v \
    --kafka_brokers localhost:9092 \
    --kafka_group_id ilagent \
    -e 'events-topic' -r 'heartbeats-topic'
```

See [Event Mapping](https://docs.ilert.com/developer-docs/client-libraries/ilagent/event-mapping) for mapping custom message fields to ilert event properties.
