9.8. 从制作者客户端使用 Service Registry 模式

这个步骤描述了如何将 Java 制作者客户端配置为使用 Service Registry 中的 schema。

步骤

  1. 为客户端配置服务注册表的 URL。

    例如:

    String registryUrl_node1 = PropertiesUtil.property(clientProperties, "registry.url.node1",
        "https://my-cluster-service-registry-myproject.example.com/api");
    RegistryService service = RegistryClient.cached(registryUrl);
  2. 使用序列化程序服务配置客户端,以及在服务注册表中查找架构的策略。

    例如:

    String registryUrl_node1 = PropertiesUtil.property(clientProperties, "registry.url.node1",
        "https://my-cluster-service-registry-myproject.example.com/api");
    
        clientProperties.put(CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG, property(clientProperties, CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG, "my-cluster-kafka-bootstrap:9092"));
        clientProperties.put(AbstractKafkaSerDe.REGISTRY_URL_CONFIG_PARAM, registryUrl_node1); 1
        clientProperties.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName()); 2
        clientProperties.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, AvroKafkaSerializer.class.getName()); 3
        clientProperties.put(AbstractKafkaSerializer.REGISTRY_GLOBAL_ID_STRATEGY_CONFIG_PARAM, FindLatestIdStrategy.class.getName()); 4
    1
    服务注册表 URL.
    2
    Service Registry 提供的消息 密钥 序列化程序服务。
    3
    Service Registry 提供的消息 序列化程序服务。
    4
    查找策略以查找架构的全局 ID。将消息的架构与服务注册表中的全局 ID(工件 ID 和 schema 版本)匹配。