Giriş
Avro için şu bağımlılığı eklemek gerekir
<dependency> <groupId>org.apache.avro</groupId> <artifactId>avro</artifactId> <version>1.11.1</version> </dependency>
IntelliJ
IntelliJ'in üretilen kodu derlemesi için çıktı dizini Source Folder olarak tanıması gerekir. Şeklen şöyle
configuration Alanına
Kod üretirken şu tagler tanımlanabilir
- sourceDirectory ve outputDirectory belirtilir
- stringType
- enableDecimalLogicalType
- fieldVisibility
- createSetters : Üretilen kodun getter/setter kullanacağı belirtilebilir. Eğer false ise Builder örüntüsü kullanılır
Örnek
Builder kullanan kod şöyledir
private InsuranceClaim generateAvroClaimRequest() { Metadata metadata = Metadata.newBuilder() .setCorrelationId(UUID.randomUUID().toString()) .setTimestamp(Instant.now()) .build(); return InsuranceClaim.newBuilder() .setClaimAmount(Precision.round(RandomUtils.nextDouble(200, 7000), 2)) .setPriority(Priority.HIGH) .setProduct(Product.MEDICAL) .setMetadata(metadata) .build(); }
goal idl-protocol
IDL tabanlı avdl uzantılı dosyalardan Java kodu üretir
Örnek
Şöyle yaparız
<plugin> <groupId>org.apache.avro</groupId> <artifactId>avro-maven-plugin</artifactId> <version>1.11.0</version> <executions> <execution> <id>avro-from-resources</id> <phase>generate-sources</phase> <goals> <goal>idl-protocol</goal> <goal>schema</goal> </goals> <configuration> <sourceDirectory>${project.basedir}/src/main/resources/avro</sourceDirectory> <outputDirectory>${project.build.directory}/generated-sources</outputDirectory> <stringType>String</stringType> <enableDecimalLogicalType>true</enableDecimalLogicalType> <fieldVisibility>private</fieldVisibility> </configuration> </execution> </executions> </plugin>
goal schema
JSON tabanlı avsc uzantılı dosyalardan Java kodu üretir
Örnek
Şöyle yaparız
<plugin><groupId>org.apache.avro</groupId><artifactId>avro-maven-plugin</artifactId><version>${avro.version}</version><executions><execution><phase>generate-sources</phase><goals><goal>schema</goal></goals><configuration><sourceDirectory>${project.basedir}/src/main/avro/</sourceDirectory><outputDirectory>${build.directory}/generated-sources</outputDirectory></configuration></execution></executions></plugin>
Örnek
Şöyle yaparız
<plugin> <groupId>org.apache.avro</groupId> <artifactId>avro-maven-plugin</artifactId> <version>${avro.version}</version> <executions> <execution> <phase>generate-sources</phase> <goals> <goal>schema</goal> </goals> <configuration> <sourceDirectory>${project.basedir}/src/main/resources/avro</sourceDirectory> <outputDirectory>${project.build.directory}/generated/avro</outputDirectory> <createSetters>false</createSetters> <enableDecimalLogicalType>true</enableDecimalLogicalType> <fieldVisibility>private</fieldVisibility> </configuration> </execution> </executions> </plugin>
mvn generate-sources
Hiç yorum yok:
Yorum Gönder