liveBook · Manning

KeyQuery

As explained in Kafka Streams in Action, Second Edition

KeyQuery is a Kafka Streams query that retrieves the result associated with an individual key.

KeyQuery represents a Kafka Streams interactive query for retrieving the state associated with one key, such as a loan category. section 13.2.1

A keyed lookup connects several pieces:

  • Create the query with the target key, such as loanType. section 13.2.1
  • Use KeyQueryMetadata to identify the partition and host responsible for that key. section 13.2.1
  • Execute the query locally through KafkaStreams.query when the current instance owns the partition; otherwise forward the request to the target host. section 13.2.1

Querying a loan category

KeyQuery<String, LoanAppRollup> keyQuery = KeyQuery.withKey(loanType); The application resolves metadata for the key, compares HostInfo values, and returns the matching LoanAppRollup through an HTTP endpoint. section 13.2.1

Listing 13.11 Creating a KeyQuery
KeyQuery<String, LoanAppRollup>
         keyQuery = KeyQuery.withKey(loanType);

Inspect the compact Java declaration that binds a String key to a LoanAppRollup result. section 13.2.1

How Kafka Streams in Action, Second Edition covers it

How deep it goes
Explains query construction, partition metadata, host comparison, local execution, and remote forwarding without detailing query internals.
Examples
Uses a loan-category key to retrieve a LoanAppRollup from a Spring Boot HTTP controller.
What you can do after
Apply it via the Kafka Streams query API to retrieve keyed state and route requests to the responsible instance.
How it connects
Connects KeyQuery with Kafka Streams, interactive queries, KeyQueryMetadata, HostInfo, and state-store queries.

This explainer was generated by Manning's knowledge graph from the text of Kafka Streams in Action, Second Edition. The section links point to the parts of the book it draws on.