pollFromKafka

Processor that serves batches of records from one Kafka topic to a client that polls over HTTP. Use CLIENT_API (the default) to serve your own API, or RELAY with relayApi to serve the fixed relay API.

Reading a batch

In either mode, dedicate a groupId to each flow that reads the topic independently. The group stores the committed position.

A batch holds at most maxBatchRecords records and about maxBatchBytes bytes. Records are ordered by partition, then offset. A record larger than maxBatchBytes is returned alone so it cannot block its partition. The processor reads up to the end of the topic as it was when the request began. If no records are available, the processor waits up to maxWaitMillis before returning an empty batch. Relay requests can set lower record and wait limits.

isolationLevel defaults to READ_COMMITTED, which skips records from open and aborted transactions.

Client API mode

A client calls an endpoint of the flow, typically served by restApi, and receives a batch of records and a cursor, the position just after the batch. The client sends the cursor back with its next request, and that confirms that it has processed every record before it:

  • The processor commits the cursor’s position to the consumer group groupId before it reads the next batch. The commit only moves forward, so a stale or repeated cursor never moves the position back.

  • A lost or failed response loses no records: the client sends the same cursor again and receives the same records again, so delivery is at least once.

  • A request without a cursor continues from the group’s committed position, or else from startPolicy. The client may come back after days.

Cursor

The cursor is an opaque string, v1. followed by the Base64URL of a JSON object with the topic and the next offset of each partition. The client must not interpret or change it. cursorExpression selects the incoming cursor from the message, for example from a query parameter or a field of the body of a restApi request. Behaviour for the cursor of a request:

  • Missing or empty: the read continues from the committed position, or else from startPolicy. When startPolicy decides, the position is committed, the batch has kafkaCursorStatus START_POLICY and the processor logs a warning.

  • For another topic, of another version, or malformed: the request fails, and the failure carries the reason.

  • Naming a partition that the topic does not have: the request fails.

  • Missing a partition that the topic has: that partition continues from its committed position, or else the start of the log. A cursor never carries over a position from a different topic.

Relay mode

Set mode = RELAY with the relayApi source. A typical use is to relay records from a lower security site to a higher security site. Leave cursorExpression unset and keep the request payload intact before this processor. The relay API uses OPAQUE cursors.

Poller lease

Only one poller can read from a relay flow at a time. A fetch response renews the lease for leaseTtlMillis. A successful RELEASE request lets a replacement poller take over immediately. If the current poller crashes without releasing the lease, the replacement must wait for it to expire. While the lease is held, the relay rejects requests from other pollers with HTTP 409 without committing their acknowledgements.

Request

The input payload is a JSON object:

  • operation: FETCH or RELEASE.

  • pollerId: The identity of the poller instance.

  • ack: Optional. The cursor up to which the poller has processed records. It is committed before reading.

  • cursor: Optional. The read position. If omitted, reading starts at ack. If neither is set, reading resumes from the committed position. If there is no committed position, startPolicy chooses where to start.

  • maxRecords: Optional. Defaults to maxBatchRecords and is capped at that value. Use 0 to renew the lease without reading records.

  • waitMillis: Optional. Defaults to maxWaitMillis and is capped at that value.

RELEASE commits ack if supplied. It ignores cursor, maxRecords and waitMillis. A payload that is not a relay request fails with HTTP 500.

{
  "operation": "FETCH",
  "pollerId": "site-a-poller-1",
  "ack": "v1.eyJ0Ijoi...",
  "cursor": "v1.eyJ0Ijoi...",
  "maxRecords": 100,
  "waitMillis": 20000
}

Output

In both modes, the payload is a list of records. Each record has a timestamp in epoch milliseconds and a cursor for the position just after that record. An exchange property carries the cursor after the batch.

valueEncoding applies to the key, value and header values. TEXT decodes them using characterSet, replacing invalid bytes with U+FFFD. Use BASE64 for binary data.

Client API output

The payload is a list with one JSON object per record:

  • key: String, nullable. The key of the record.

  • value: String, nullable. The value of the record.

  • headers: list of objects with name (String) and value (String, nullable). Empty when there are none.

  • timestamp: Number (long). The timestamp of the record, in milliseconds since the epoch.

  • topic: String. The topic of the record.

  • partition: Number (integer). The partition of the record.

  • offset: Number (long). The offset of the record.

  • cursor: String. The cursor for the position just after the record.

The processor sets these exchange properties for the response mapping:

  • kafkaNextCursor: the cursor to return to the client, the position after the batch. For an empty batch it is the position the request started at.

  • kafkaHasMore: true when records were available beyond the batch at the time of the request.

  • kafkaRecordCount: the number of records in the batch.

  • kafkaGaps: a JSON list of retention gaps ( partition, requestedOffset, and earliestOffset), or [] if there are no gaps.

  • kafkaCursorStatus: NORMAL, START_POLICY when the position came from startPolicy, or GAP when retention removed a requested position.

Payload of the output:

[
  {
    "key": "crew-4711",
    "value": "{\"status\": \"EnRoute\"}",
    "headers": [ { "name": "messageType", "value": "CrewStatus" } ],
    "timestamp": 1762934400000,
    "topic": "crew-updates",
    "partition": 0,
    "offset": 1042,
    "cursor": "v1.eyJ0b3BpYyI6ImNyZXctdXBkYXRlcyIsIm9mZnNldHMiOnsiMCI6MTA0M319"
  }
]

Exchange properties of the output:

kafkaNextCursor = v1.eyJ0b3BpYyI6ImNyZXctdXBkYXRlcyIsIm9mZnNldHMiOnsiMCI6MTA0M319
kafkaHasMore = false
kafkaRecordCount = 1
kafkaGaps = []
kafkaCursorStatus = NORMAL

Shaping the client response

A processor after pollFromKafka, such as map or setPayload, builds the response in the client’s own format from the payload and the exchange properties. The result must keep these rules:

  • The client must receive kafkaNextCursor, or the cursor of the last record it processed, unchanged. A changed cursor corrupts the acknowledgement.

  • The processors must be free of side effects, because a batch is transformed again each time it is read again, for example after a lost response.

Relay output

A relayed record has key, payload, attributes, timestamp, orderingKey and cursor. It does not expose the Kafka topic, partition or offset as separate fields. relayApi builds the response using the payload and the relayNextCursor, relayHasMore, relayLostRecords, relayLease and relayPayloadEncoding exchange properties. Use map to change or filter records without side effects. Keep the timestamp and cursor of each record you keep. The batch cursor still advances past any records you filter out.

Failure

A request that fails, for example an invalid cursor, an unreachable broker or a Kafka call that exceeds kafkaTimeoutMillis, ends the message as failed, with the reason and the cause. The acknowledgement may already be committed when a read fails: it is the cursor in CLIENT_API mode and ack in RELAY mode. Retry with the same request.

Restrictions

A flow with this processor:

  • uses flowPipelineDeploymentStrategy { scope = SINGLETON }, so that one consumer owns the topic.

  • uses the RequestResponse exchange pattern, or Headless when another flow calls it, for example with distribute. A OneWay flow has no response to carry the batch.

  • has at most one pollFromKafka. Each client that reads a topic needs its own flow and groupId.

  • has no processingStrategy on the processor.

  • unless it is Headless, sets redeliveryStrategy { redeliveryMaxNo = 0 }, because a redelivery would only rerun the same poll and delay the error response, and a redeliveryMillis above maxWaitMillis + kafkaTimeoutMillis + 1 second, because the source fails an unanswered request 1 second before redeliveryMillis. The default redeliveryMillis of 15 seconds is enough with the default kafkaTimeoutMillis of 5 seconds and maxWaitMillis 0. The validation message names the smallest redeliveryMillis allowed.

In CLIENT_API mode, send one request at a time and retry with the same cursor after an error.

Client API example

A flow where a client posts the cursor it received last and gets the next batch back:

flowConfig {
    id = "crew-updates-pull"
    ownerId = "my-owner"
    exchangePattern = RequestResponse
    flowPipelineDeploymentStrategy { scope = SINGLETON }
    redeliveryStrategy { redeliveryMaxNo = 0 }

    restApi {
        id = "pull-api"
        resourceClass = "com.example.PullRequest"
    }

    pollFromKafka {
        id = "read-crew-updates"
        brokerList = "kafka-0.kafka:9093"
        topic = "crew-updates"
        groupId = "crew-updates-pull.client-a"
        authenticationConfigKey = "cloudKafka"
        cursorExpression = "jsoniq:#input.envelope.payload.cursor"
        startPolicy = EARLIEST
        maxBatchRecords = 500
    }

    map {
        id = "to-response"
        // Build the client's response from the payload and the kafka* exchange properties.
    }
}

Properties

Name Summary

brokerList

A list of host/port pairs to use for establishing the initial connection to the Kafka cluster. This string must be in the form of host1:port1,host2:port2, etc. Required.

topic

Name of the one topic to read. Required.

groupId

The consumer group whose committed offsets hold the client’s position. Dedicate the group to this flow: no other consumer may ever subscribe with it. Each client that reads the topic independently needs its own flow and groupId. Required.

clientId

An ID string to pass to the server when making requests, so that server-side request logs name the application. Optional.

authenticationConfigKey

A secret key the server uses to look up credentials needed for connecting to the Kafka broker. Optional and uses no authentication by default.

mode

CLIENT_API serves your own API. RELAY serves the fixed API of the relayApi source. Defaults to CLIENT_API.

leaseTtlMillis

In RELAY mode, how long the relay waits after answering a fetch before another poller can take over. Set it higher than the poller’s receiveTimeoutMillis plus its retry backoff. Defaults to 60_000 milliseconds (60 seconds). CLIENT_API accepts the default but does not use it. Other values are rejected.

cursorExpression

The JSONiq or SpEL expression that selects the incoming cursor from the message, for example a query parameter or a field of the request body. In CLIENT_API mode this setting is optional. If the expression returns no cursor or an empty cursor, reading resumes from the committed position, or from startPolicy if there is none. In RELAY mode leave this setting unset. Even an empty expression is rejected.

cursorFormat

How the cursor is written in the client’s API. Currently only OPAQUE. Optional and defaults to OPAQUE.

startPolicy

Where a request without a position starts when the consumer group has no committed offset:

  • EARLIEST: the first record the topic still holds.

  • LATEST: after the last record the topic holds now.

It never applies to a position below the start of the topic. Optional and defaults to EARLIEST.

maxBatchRecords

Maximum number of records in one batch, from 1 to 1000. Optional and defaults to 100.

maxBatchBytes

Maximum size in bytes of the records in one batch, which limits memory use and response size. A record larger than the limit is still returned, on its own, so that it never blocks a partition. The serialized response is larger than the records: BASE64 adds up to a third. Optional and defaults to 1_048_576 (1 MB).

maxWaitMillis

Maximum time in milliseconds to wait for records when none are available. Optional and defaults to 0: an empty topic returns an empty batch at once.

kafkaTimeoutMillis

Time limit in milliseconds for the Kafka calls of one request, not counting the wait for records. A request that exceeds it fails. Optional and defaults to 5_000.

valueEncoding

How record keys, values and header values are written in the batch:

  • TEXT: decoded with characterSet.

  • BASE64: encoded as Base64, for binary records.

Optional and defaults to TEXT.

characterSet

Character set for TEXT decoding. Bytes that are invalid in it become the replacement character U+FFFD. Optional and defaults to UTF-8.

isolationLevel

The Kafka isolation.level: READ_COMMITTED skips records of open and aborted transactions. Optional and defaults to READ_COMMITTED.

retainPayloadOnFailure

Whether the incoming payload is available for error processing on failure. Defaults to false.

name

Optional, descriptive name for the processor.

id

Required identifier of the processor, unique across all processors within the flow. Must be between 3 and 30 characters long; contain only lower and uppercase alphabetical characters (a-z and A-Z), numbers, dashes ("-"), and underscores ("_"); and start with an alphabetical character. In other words, it adheres to the regex pattern [a-zA-Z][a-zA-Z0-9_-]{2,29}.

exchangeProperties

Optional set of custom properties in a simple jdk-format, that are added to the message exchange properties before processing the incoming payload. Any existing properties with the same name will be replaced by properties defined here.

Sub-builders

Name Summary

inboundTransformationStrategy

Strategy that customizes the conversion of an incoming payload by a processor (e.g., string to object). Should be used when the processor’s default conversion logic cannot be used.

messageLoggingStrategy

Strategy for describing how a processor’s message is logged on the server.

payloadArchivingStrategy

Strategy for archiving payloads.