IDEA avsc文件生成实体类

avsc文件生成实体类

pom.xml 加入 配置
<project>	
		<dependencies>
        
        <dependency>
            <groupId>org.apache.avrogroupId>
            <artifactId>avroartifactId>
            <version>1.8.0version>
        dependency>
    dependencies>

    <build>
        <plugins>
            
            <plugin>
                <groupId>org.apache.avrogroupId>
                <artifactId>avro-maven-pluginartifactId>
                <version>1.8.0version>
                <executions>
                    <execution>
                        <phase>generate-sourcesphase>
                        <goals>
                            <goal>schemagoal>
                        goals>
                        <configuration>
                            <sourceDirectory>${project.basedir}/src/main/avro/sourceDirectory>
                            <outputDirectory>${project.basedir}/src/main/java/outputDirectory>
                        configuration>
                    execution>
                executions>
            plugin>
            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-compiler-pluginartifactId>
                <configuration>
                    <source>8source>
                    <target>8target>
                configuration>
            plugin>
        plugins>
    build>
 
    <repositories>
        <repository>
            <id>confluentid>
            <url>http://packages.confluent.io/maven/url>
        repository>
    repositories>
project>
main目录下生成avro目录,并放入要转换实体类的json文件

IDEA avsc文件生成实体类_第1张图片

{
  "namespace": "com.zzw.pojo",    // 实体类存放路径
  "type": "record",
  "name": "User",                 // 实体类文件名
  "fields": [                     // 实体类属性
    {"name": "name", "type": "string"},                     // 实体类属性名和类型
    {"name": "favorite_number",  "type": ["int", "null"]},
    {"name": "favorite_color", "type": ["string", "null"]}
  ]
}
通过mvn compile 生成实体类

IDEA avsc文件生成实体类_第2张图片

avsc文件生成实体类

pom.xml 加入 配置
<project>	
		<dependencies>
        
        <dependency>
            <groupId>org.apache.avrogroupId>
            <artifactId>avroartifactId>
            <version>1.8.0version>
        dependency>
    dependencies>

    <build>
        <plugins>
            
            <plugin>
                <groupId>org.apache.avrogroupId>
                <artifactId>avro-maven-pluginartifactId>
                <version>1.8.0version>
                <executions>
                    <execution>
                        <phase>generate-sourcesphase>
                        <goals>
                            <goal>schemagoal>
                        goals>
                        <configuration>
                            <sourceDirectory>${project.basedir}/src/main/avro/sourceDirectory>
                            <outputDirectory>${project.basedir}/src/main/java/outputDirectory>
                        configuration>
                    execution>
                executions>
            plugin>
            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-compiler-pluginartifactId>
                <configuration>
                    <source>8source>
                    <target>8target>
                configuration>
            plugin>
        plugins>
    build>
 
    <repositories>
        <repository>
            <id>confluentid>
            <url>http://packages.confluent.io/maven/url>
        repository>
    repositories>
project>
main目录下生成avro目录,并放入要转换实体类的json文件

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-0aGSmN9p-1630728159527)(kafka.assets/image-20210904115620872.png)]

{
  "namespace": "com.zzw.pojo",    // 实体类存放路径
  "type": "record",
  "name": "User",                 // 实体类文件名
  "fields": [                     // 实体类属性
    {"name": "name", "type": "string"},                     // 实体类属性名和类型
    {"name": "favorite_number",  "type": ["int", "null"]},
    {"name": "favorite_color", "type": ["string", "null"]}
  ]
}
通过mvn compile 生成实体类

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-ns8Cp2Ek-1630728159530)(kafka.assets/image-20210904115917357.png)]

你可能感兴趣的:(Java,kafka,idea,maven,java,KAFKA)