简体   繁体   English

AVRO 生成的 pojo's + Kafka + Spring Cloud Schema Registry

[英]AVRO Generated pojo's + Kafka + Spring Cloud Schema Registry

I am considering using schema's to validate data on my kafka topics.我正在考虑使用模式来验证我的 kafka 主题上的数据。 I am exploring spring cloud schema registry in combination with apache kafka.我正在结合 apache kafka 探索spring 云模式注册表

If I have understood correctly after reading the docs.如果我在阅读文档后理解正确。 Spring cloud schema registry supports avro schema's only ! Spring 云模式注册表仅支持 avro 模式! In avro pojos need to be generated using .avsc files on the classpath and that there is a maven plugin which does the needful.在 avro 中,需要使用类路径上的.avsc文件生成 pojos,并且有一个 maven 插件可以满足需要。

Problem:问题:

What if I have custom validations on my pojos's like this?如果我像这样对我的 pojo 进行自定义验证怎么办? I would not like generated this pojo in my kafka consumer using avro schema as then I loose my validations.我不希望使用 avro 模式在我的 kafka 消费者中生成这个 pojo,因为这样我就失去了验证。 Did anyone come across similar issues?有没有人遇到过类似的问题? If so how did you resolve it?如果是这样,你是如何解决的?

public class Pojo implements Serializable {

 @Color
 private String colour;
 .....
@Target({ElementType.FIELD, ElementType.PARAMETER, ElementType.TYPE_USE})
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = ColorValidator.class)
public @interface Color {
 .....
public class ColorValidator implements ConstraintValidator<Color, String> {
......

What if I have custom validations on my pojos如果我的 pojo 有自定义验证怎么办

You can still define ConstraintValidator implementations if you generate POJOs from schema files.如果您从模式文件生成 POJO,您仍然可以定义ConstraintValidator实现。

In other words, you make the AVSC, and use the avro-maven-plugin to create the classes ( mvn compile ), and then the classpath will have the classes available to define the constraint validators.换句话说,您制作 AVSC,并使用avro-maven-plugin创建类 ( mvn compile ),然后类路径将具有可用于定义约束验证器的类。

You might want to look at the CustomEncoding class for actually validating Avro objects, though.不过,您可能想查看CustomEncoding class 以实际验证 Avro 对象。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Spring 启动应用程序中使用来自 Confluent 的模式注册表与 Avro 和 Kafka - Using Schema Registry from Confluent with Avro and Kafka in Spring Boot Applications 使用默认架构注册表客户端而不是Avro架构注册表客户端的Spring Cloud Stream问题 - Issue with Spring Cloud Stream using the Default Schema Registry client instead of the Avro Schema Registry client 错误序列化 Avro 消息 - Kafka Schema Registry - Error serializing Avro message - Kafka Schema Registry Spring 使用 Glue 模式注册表反序列化 AVRO GENERIC_RECORD 启动 kafka 消费者问题 - Spring boot kafka consumer issue deserializing AVRO GENERIC_RECORD using Glue schema registry Spring / Avro - 使用融合模式注册表 - Spring / Avro - using confluent schema registry 无法使用Confluent Schema Registry和Spring Cloud Streams反序列化Avro消息 - Unable to deserialize Avro message using Confluent Schema Registry and Spring Cloud Stream 将 java POJO 转换为 Avro 模式对象,然后通过 KafkaTemplate 发送到 kafka 服务器 - Convert java POJO to Avro schema object then send to kafka server by KafkaTemplate 找不到 Spring kafka AVRO 生成的类 - Spring kafka AVRO generated class not found Confluent Cloud Schema Registry Unauthorized错误的spring-cloud-stream-binder-kafka配置 - spring-cloud-stream-binder-kafka configuration for Confluent Cloud Schema Registry Unauthorized error 如何使用 Avro 序列化程序和架构注册表向 Kafka 发送消息 - How to send message to Kafka with Avro serializer and schema registry
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM