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
groupIdbefore 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. WhenstartPolicydecides, the position is committed, the batch haskafkaCursorStatusSTART_POLICYand 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:FETCHorRELEASE. -
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 atack. If neither is set, reading resumes from the committed position. If there is no committed position,startPolicychooses where to start. -
maxRecords: Optional. Defaults tomaxBatchRecordsand is capped at that value. Use0to renew the lease without reading records. -
waitMillis: Optional. Defaults tomaxWaitMillisand 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 withname(String) andvalue(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:truewhen 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, andearliestOffset), or[]if there are no gaps. -
kafkaCursorStatus:NORMAL,START_POLICYwhen the position came fromstartPolicy, orGAPwhen 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 thecursorof 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
RequestResponseexchange pattern, orHeadlesswhen another flow calls it, for example withdistribute. AOneWayflow has no response to carry the batch. -
has at most one
pollFromKafka. Each client that reads a topic needs its own flow andgroupId. -
has no
processingStrategyon the processor. -
unless it is
Headless, setsredeliveryStrategy { redeliveryMaxNo = 0 }, because a redelivery would only rerun the same poll and delay the error response, and aredeliveryMillisabovemaxWaitMillis+kafkaTimeoutMillis+ 1 second, because the source fails an unanswered request 1 second beforeredeliveryMillis. The defaultredeliveryMillisof 15 seconds is enough with the defaultkafkaTimeoutMillisof 5 seconds andmaxWaitMillis0. The validation message names the smallestredeliveryMillisallowed.
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 |
|---|---|
|
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 |
|
Name of the one topic to read. Required. |
|
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 |
|
An ID string to pass to the server when making requests, so that server-side request logs name the application. Optional. |
|
A secret key the server uses to look up credentials needed for connecting to the Kafka broker. Optional and uses no authentication by default. |
|
|
|
In |
|
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 |
|
How the cursor is written in the client’s API. Currently only |
|
Where a request without a position starts when the consumer group has no committed offset:
It never applies to a position below the start of the topic. Optional and defaults to |
|
Maximum number of records in one batch, from 1 to 1000. Optional and defaults to |
|
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: |
|
Maximum time in milliseconds to wait for records when none are available. Optional and defaults to |
|
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 |
|
How record keys, values and header values are written in the batch:
Optional and defaults to |
|
Character set for |
|
The Kafka |
|
Whether the incoming payload is available for error processing on failure. Defaults to |
|
Optional, descriptive name for the processor. |
|
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 |
|
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 |
|---|---|
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. |
|
Strategy for describing how a processor’s message is logged on the server. |
|
Strategy for archiving payloads. |