7.6. 使用 Kafka Streams 应用程序的模式
这个步骤描述了如何配置使用 Java 编写的 Kafka Streams 客户端,以使用 Service Registry 中的 Apache Avro 模式。
先决条件
- 已安装 Service Registry
- 模式在 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 配置序列化器和反序列化器:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1.Service Registry 提供的 Avro serializer。
- 2.Service Registry 提供的 Avro deserializer。
- 3.配置 Service Registry URL 和 Avro 读取器以 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