Skip to main content

Kafka Service

The kafka active variable service reads JSON messages from Apache Kafka topics and returns them as a list of objects, the same shape the JSON service returns for a JSON array.

Using the service​

messages = ${kafka:"prices-*","bootstrap=b-1.example.com:9196;b-2.example.com:9196,group=nge_prices,username=nge_reader"}

The id is a topic name, several topic names separated by ;, or a pattern: an id with * is a wildcard pattern, and an id starting with ^ is a regular expression.

Each read returns the messages published since the consumer group last read the topic, up to maxRecords. A message that is a JSON array gives one object per element.

Options​

Options are given after the id as name=value pairs separated by commas. Use ; to separate several values inside one option.

OptionDescriptionDefault
bootstrapThe broker list, e.g. b-1:9196;b-2:9196 (required)
groupThe consumer group id (required)
usernameThe SASL username
passwordThe SASL password. Without it, the KAFKA_SASL_PASSWORD environment variable is used
protocolSASL_SSL, SSL, SASL_PLAINTEXT or PLAINTEXTSASL_SSL
mechanismSCRAM-SHA-512, SCRAM-SHA-256 or PLAINSCRAM-SHA-512
maxRecordsThe most messages returned by one read1000
maxWaitThe most milliseconds one read can take30000
idleTimeoutStop after this many milliseconds with no new messages3000
offsetResetearliest or latest: where a new consumer group startsearliest
committrue or false: whether to record that the returned messages have been readtrue
metadatatrue adds _topic, _partition, _offset, _key and _timestamp to each objectfalse
failOnBadMessagetrue fails the read on a message that is not JSON, instead of skipping itfalse
kafka.nameAny Kafka consumer property, e.g. kafka.fetch.max.bytes=52428800
caution

With commit=true, the messages are marked as read before the read returns. If your script fails afterwards, those messages are not read again. Use commit=false while you test.