# stormbreaker-kafka

> Load through a topic: a stream's records become whole Kafka records (key, value, headers), published at a declared arrival rate through a Kafka service axx's kafka pack declared, serialized as its publish steps serialize: Avro, with the Schema Registry, when the record's factory is Avro; text otherwise.

Source: https://stormbreaker.nimbusxr.us/next/references/packs/stormbreaker-kafka/

Load through a topic: a stream's records become whole Kafka records (key, value, headers), published at a declared arrival rate through a Kafka service axx's kafka pack declared, serialized as its publish steps serialize: Avro, with the Schema Registry, when the record's factory is Avro; text otherwise. Builds on stormbreaker-core (list it in axx-packs.yaml): binding a stream declares the identities it will create before anything is published.

## Add it

List it in the project's `axx-packs.yaml`, with the packs it builds on:

```yaml title="axx-packs.yaml"
packs:
  - kafka
  - github.com/nimbusxr/stormbreaker/packs/core@v0.1.0
  - github.com/nimbusxr/stormbreaker/packs/kafka@v0.1.0
```

## Settings

In `axx.yaml`, under `packs.stormbreaker-kafka`:

| Setting | What it is |
|---|---|
| `maxDrift` | How late events may leave their due time, for five seconds in a row, before the publish stops, failing because the driver is not keeping up (default 1s; off turns it off). |
| `maxInFlight` | How many events may be in flight before the publish stops, failing because the cluster is not keeping up (default 50000). |

## Steps

### `stormbreaker.kafka.stream`

```gherkin
Given the {word} stream of {word} kafka events[[ on the {word} kafka service]]
```

Bind a stream (`<name>.stream.yaml`) to a topic: each record is an event, its data the value. Binding declares every identity the stream will create, at the topic, before anything is published.

```gherkin
Given the scans stream of depot-scans kafka events
```

### `stormbreaker.kafka.stream.keys`

```gherkin
Given the {word} stream kafka event keys are the {word} metadata
```

Take each event's key from a metadata entry of its record. Without one, an event's key is its record's first identity.

### `stormbreaker.kafka.stream.headers`

```gherkin
Given the {word} stream kafka event headers are the {word} metadata
```

Take each event's headers from a metadata entry of its record: a map, by header name.

### `stormbreaker.kafka.identified.payload`

```gherkin
Given the {word} kafka events are identified by the payload {word}
```

Declare the identities in the payloads of the events drafted by hand for a topic before each is published: the values at the JSON paths given, comma-separated.

### `stormbreaker.kafka.identified.header`

```gherkin
Given the {word} kafka events are identified by the header {word}
```

Declare the identities in a header of the events drafted by hand for a topic before each is published.

### `stormbreaker.kafka.stream.publish`

```gherkin
When the {word} stream is published at {int} events per second
```

Publish the stream's events open-model: event i is due at i/rate seconds, however the ones before it are doing.

```gherkin
When the scans stream is published at 25 events per second
```

### `stormbreaker.kafka.stream.publish.schema`

```gherkin
When the {word} stream is published using schema {filepath} at {int} events per second
```

Publish the stream's events as values of an Avro schema, whatever their factory says.

```gherkin
When the scans stream is published using schema schemas/depot-scan.avsc at 25 events per second
```

### `stormbreaker.kafka.caught-up`

```gherkin
Then the {word} consumer group catches up on the {word} topic within {duration}[[ on the {word} kafka service]]
```

Wait until a consumer group has consumed everything published to a topic (its lag is zero on every partition), so that what is downstream has settled before it is judged, and before cleanup. Fails when it has not caught up in time.

```gherkin
Then the tracking consumer group catches up on the parcel-events topic within 60s
```

### `stormbreaker.kafka.no-failures`

```gherkin
Then the publish completes with no failed events
```

Check that no event of the last publish failed.

```gherkin
Then the publish completes with no failed events
```
