7.6. 使用 Kafka Streams 应用程序的 schema
此流程描述了如何配置以 Java 编写的 Kafka Streams 客户端,以使用 Service Registry 的 Apache Avro 模式。
先决条件
- 已安装 Service Registry
- 该 schema 使用 Service Registry 注册
流程
使用 Service Registry URL 创建并配置 Java 客户端:
String registryUrl = "https://registry.example.com/apis/registry/v2"; RegistryService client = RegistryClient.cached(registryUrl);
String registryUrl = "https://registry.example.com/apis/registry/v2"; RegistryService client = RegistryClient.cached(registryUrl);
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 配置 serializer 和 deserializer:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1. Service Registry 提供的 Avro serializer。
- 2.Service Registry 提供的 Avro deserializer。
- 3.以 Avro 格式配置 Service Registry URL 和 Avro 读取器进行反序列化。
创建 Kafka Streams 客户端:
KStream<String, LogInput> input = builder.stream( INPUT_TOPIC, Consumed.with(Serdes.String(), logSerde) );
KStream<String, LogInput> input = builder.stream( INPUT_TOPIC, Consumed.with(Serdes.String(), logSerde) );
Copy to Clipboard Copied! Toggle word wrap Toggle overflow