liveBook · Manning

Query interface

As explained in Kafka Streams in Action, Second Edition

The Query interface is the Kafka Streams contract implemented by objects that describe state-store queries.

The Query<R> interface is the Kafka Streams contract implemented by objects that describe queries against state stores. It sits inside an Interactive Queries application that exposes loan-processing state through HTTP. section 13.2.1

A query-driven application typically combines these pieces:

  • Create a typed query such as KeyQuery<String, LoanAppRollup> with the target key. section 13.2.1
  • Place the query in a StateQueryRequest for a named store and selected partitions. section 13.2.1
  • Extract QueryResult values and return them through a REST controller, querying another host when the target partition is remote. section 13.2.1

Loan-category lookup

A controller receives a loan category, creates a KeyQuery for that category, resolves its KeyQueryMetadata, and queries the owning partition for a LoanAppRollup. If another instance owns the partition, it forwards the request to that host. section 13.2.1

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

Inspect the compact Java construction of a typed KeyQuery. section 13.2.1

How Kafka Streams in Action, Second Edition covers it

How deep it goes
Defines the query contract and demonstrates construction, partition targeting, result extraction, and remote routing.
Examples
Uses loan-category lookups returning LoanAppRollup values through a Spring Boot REST controller.
What it assumes
Assumes a Kafka Streams application with a queryable state store and develops the HTTP exposure and routing around it.
What you can do after
Build an Interactive Queries endpoint that creates typed queries, locates partitions, retrieves results, and handles remote instances.
How it connects
Links Kafka Streams, state stores, Interactive Queries, KeyQuery, StateQueryRequest, partitions, and REST controllers.

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.