Reputation: 14134
Following the tutorial about Kafka Streams located at: https://github.com/confluentinc/kafka-streams-examples/blob/4.0.0-post/src/main/java/io/confluent/examples/streams/WikipediaFeedAvroExample.java
There is a line:
import io.confluent.examples.streams.avro.WikiFeed
As I suppose it relates to this file: https://github.com/confluentinc/kafka-streams-examples/blob/4.0.0-post/src/main/resources/avro/io/confluent/examples/streams/wikifeed.avsc
resource
not java
folder?The other import is even more fantastic:
import io.confluent.kafka.serializers.AbstractKafkaAvroSerDeConfig;
kafka
folder in the java/io/confluent
folder.How does all this magic suppose to work?
Upvotes: 3
Views: 910
Reputation: 13181
The WikiFeed
class is created dynamically at build time using the avro-maven-plugin
from the .avsc file you linked to. You can check how it's configured in the <plugins>
section of pom.xml.
The AbstractKafkaAvroSerDeConfig
class comes from the kafka-avro-serializer
dependency. Eclipse has a nice way of navigating from the individual class in the Editor view back to the Package Explorer which includes the Maven dependencies, like this:
Upvotes: 1
Reputation: 85779
The magic is made by avro-maven-plugin which you can find in the pom.xml:
<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>src/main/resources/avro/io/confluent/examples/streams</sourceDirectory>
<outputDirectory>${project.build.directory}/generated-sources</outputDirectory>
<stringType>String</stringType>
</configuration>
</execution>
</executions>
</plugin>
Quoting from the documentation of the plugin:
Simple integration with dynamic languages. Code generation is not required to read or write data files nor to use or implement RPC protocols. Code generation as an optional optimization, only worth implementing for statically typed languages.
This is, at pre compile time, the plugin reads the content of avsc files and generate binary sources (for this case, Java classes) that then can be used in the code.
You can see the code generated by the plugin in target/generated-sources
. There will be a folder structure and proper java (not class) files there.
Upvotes: 2