Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic avro converter #159

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions examples/maven-spring-avro/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea
target
src/main/frontend/generated
34 changes: 34 additions & 0 deletions examples/maven-spring-avro/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
## Wirespec Maven Plugin Configuration
```xml
<plugin>
<groupId>community.flock.wirespec.plugin.maven</groupId>
<artifactId>wirespec-maven-plugin</artifactId>
<version>0.0.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>community.flock.wirespec.integration</groupId>
<artifactId>avro-jvm</artifactId>
<version>0.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>java</id>
<goals>
<goal>custom</goal>
</goals>
<configuration>
<input>${project.basedir}/src/main/wirespec</input>
<output>${project.build.directory}/generated-sources</output>
<emitterClass>community.flock.wirespec.integration.avro.java.emit.AvroEmitter</emitterClass>
<shared>Java</shared>
<extension>java</extension>
<packageName>community.flock.wirespec.generated.examples.spring</packageName>
</configuration>
</execution>
</executions>
</plugin>
```

Find the [actual pom.xml](app/pom.xml) in the `app` module and the
[custom emitter](emitter/src/main/java/community/flock/wirespec/emit/CustomEmitter.java) in the `emitter` module
147 changes: 147 additions & 0 deletions examples/maven-spring-avro/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>community.flock.wirespec.example.maven</groupId>
<artifactId>examples</artifactId>
<version>0.0.0-SNAPSHOT</version>
</parent>

<artifactId>maven-spring-avro</artifactId>

<repositories>
<repository>
<id>confluent</id>
<url>https://packages.confluent.io/maven/</url>
</repository>
</repositories>

<dependencies>

<dependency>
<groupId>community.flock.wirespec.integration</groupId>
<artifactId>avro-jvm</artifactId>
<version>0.0.0-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
</dependency>
<dependency>
<groupId>io.confluent</groupId>
<artifactId>kafka-avro-serializer</artifactId>
<version>7.7.1</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.avro</groupId>
<artifactId>avro</artifactId>
<version>1.11.3</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-testcontainers</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>kafka</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test</artifactId>
<version>${kotlin.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>community.flock.wirespec.plugin.maven</groupId>
<artifactId>wirespec-maven-plugin</artifactId>
<version>0.0.0-SNAPSHOT</version>
<executions>
<execution>
<id>test_metadata</id>
<goals>
<goal>custom</goal>
</goals>
<configuration>
<input>${project.basedir}/src/main/avro/test_metadata.avsc</input>
<output>${project.build.directory}/generated-sources</output>
<format>Avro</format>
<emitterClass>community.flock.wirespec.integration.avro.java.emit.AvroJavaEmitter</emitterClass>
<shared>Java</shared>
<extension>java</extension>
<packageName>com.eventloopsoftware.kafka.model</packageName>
</configuration>
</execution>
<execution>
<id>test_avro_001</id>
<goals>
<goal>custom</goal>
</goals>
<configuration>
<input>${project.basedir}/src/main/avro/test_avro_001.avsc</input>
<output>${project.build.directory}/generated-sources</output>
<format>Avro</format>
<emitterClass>community.flock.wirespec.integration.avro.java.emit.AvroJavaEmitter</emitterClass>
<shared>Java</shared>
<extension>java</extension>
<packageName>com.eventloopsoftware</packageName>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>21</release>
<compilerArgs>--enable-preview</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>
</project>
99 changes: 99 additions & 0 deletions examples/maven-spring-avro/src/main/avro/test_avro_001.avsc
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
{
"type": "record",
"name": "TestAvroRecord",
"namespace": "com.eventloopsoftware",
"fields": [
{
"name": "metadata",
"type": "com.eventloopsoftware.kafka.model.TestAvroMetadata"
},
{
"name": "order",
"type": {
"type": "record",
"name": "TestAvroOrder",
"fields": [
{
"name": "number",
"type": "string",
"doc": "Unique identifier of the order"
},
{
"name": "qr_code",
"type": "bytes",
"doc": "QR code"
},
{
"name": "created_at",
"type": [
"null",
{
"type": "long",
"logicalType": "timestamp-millis"
}
],
"doc": "Order creation data"
},
{
"name": "ref_numbers",
"type": {
"type": "array",
"items": {
"type": "record",
"name": "TestAvroRefNumber",
"fields": [
{
"name": "number",
"type": "string",
"doc": "Reference number"
},
{
"name": "enum_identifier",
"type": {
"type": "enum",
"name": "TestAvroEnumIdentifier",
"symbols": [
"REF_1",
"REF_2",
"REF_3"
]
}
}
]
}
}
},
{
"name": "lines",
"type": {
"type": "array",
"items": {
"type": "record",
"name": "TestAvroOrderLines",
"fields": [
{
"name": "id",
"type": {
"type": "string",
"logicalType": "uuid"
},
"doc": "Order line ID"
},
{
"name": "amount",
"type": "float",
"doc": "Amount"
}
]
}
}
},
{
"name": "a_number",
"type": "long"
}
]
}
}
]
}
23 changes: 23 additions & 0 deletions examples/maven-spring-avro/src/main/avro/test_metadata.avsc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"type": "record",
"name": "TestAvroMetadata",
"namespace": "com.eventloopsoftware.kafka.model",
"fields": [
{
"name": "id",
"doc": "ID docs",
"type": {
"type": "string",
"logicalType": "uuid"
}
},
{
"name": "created",
"doc": "Timestamp e.g., 1 January 1970 00:00:00.000 UTC.",
"type": {
"type": "long",
"logicalType": "timestamp-millis"
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package community.flock.wirespec.examples.maven.avro;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class AvroExampleApplication {

public static void main(String[] args) {
SpringApplication.run(AvroExampleApplication.class, args);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package community.flock.wirespec.examples.maven.avro;

import io.confluent.kafka.serializers.KafkaAvroDeserializer;
import io.confluent.kafka.serializers.KafkaAvroDeserializerConfig;
import io.confluent.kafka.serializers.KafkaAvroSerializer;
import org.apache.avro.generic.GenericRecord;
import org.apache.kafka.clients.consumer.ConsumerConfig;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.common.serialization.StringDeserializer;
import org.apache.kafka.common.serialization.StringSerializer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.kafka.KafkaProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.kafka.core.ConsumerFactory;
import org.springframework.kafka.core.DefaultKafkaConsumerFactory;
import org.springframework.kafka.core.DefaultKafkaProducerFactory;
import org.springframework.kafka.core.ProducerFactory;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class AvroExampleConfiguration {

@Autowired
private KafkaProperties kafkaProperties;

@Bean
public ProducerFactory<Object, Object> kafkaProducerFactory() {
Map<String, Object> props = new HashMap<>(kafkaProperties.getProperties());
props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, kafkaProperties.getBootstrapServers());
props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, KafkaAvroSerializer.class);
return new DefaultKafkaProducerFactory<>(props);
}

@Bean
public ConsumerFactory<Object, Object> kafkaConsumerFactory() {
Map<String, Object> props = new HashMap<>(kafkaProperties.getProperties());
props.put(ConsumerConfig.GROUP_ID_CONFIG, "group");
props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, kafkaProperties.getBootstrapServers());
props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, KafkaAvroDeserializer.class);
return new DefaultKafkaConsumerFactory<>(props);
}
}
Loading
Loading