简体   繁体   中英

AVRO Generated pojo's + Kafka + Spring Cloud Schema Registry

I am considering using schema's to validate data on my kafka topics. I am exploring spring cloud schema registry in combination with apache kafka.

If I have understood correctly after reading the docs. Spring cloud schema registry supports avro schema's only ! In avro pojos need to be generated using .avsc files on the classpath and that there is a maven plugin which does the needful.

Problem:

What if I have custom validations on my pojos's like this? I would not like generated this pojo in my kafka consumer using avro schema as then I loose my validations. 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

You can still define ConstraintValidator implementations if you generate POJOs from schema files.

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.

You might want to look at the CustomEncoding class for actually validating Avro objects, though.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM