[英]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.