Skip to content

Commit 72792ef

Browse files
authored
Simplify registry quickstart (#327)
1 parent bb622e5 commit 72792ef

15 files changed

Lines changed: 794 additions & 0 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Eclipse
2+
.project
3+
.classpath
4+
.settings/
5+
bin/
6+
7+
# IntelliJ
8+
.idea
9+
*.ipr
10+
*.iml
11+
*.iws
12+
13+
# NetBeans
14+
nb-configuration.xml
15+
16+
# Visual Studio Code
17+
.vscode
18+
19+
# OSX
20+
.DS_Store
21+
22+
# Vim
23+
*.swp
24+
*.swo
25+
26+
# patch
27+
*.orig
28+
*.rej
29+
30+
# Maven
31+
target/
32+
pom.xml.tag
33+
pom.xml.releaseBackup
34+
pom.xml.versionsBackup
35+
release.properties
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*
2+
* Copyright 2007-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
import java.net.*;
17+
import java.io.*;
18+
import java.nio.channels.*;
19+
import java.util.Properties;
20+
21+
public class MavenWrapperDownloader {
22+
23+
private static final String WRAPPER_VERSION = "0.5.6";
24+
/**
25+
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
26+
*/
27+
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
28+
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
29+
30+
/**
31+
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
32+
* use instead of the default one.
33+
*/
34+
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
35+
".mvn/wrapper/maven-wrapper.properties";
36+
37+
/**
38+
* Path where the maven-wrapper.jar will be saved to.
39+
*/
40+
private static final String MAVEN_WRAPPER_JAR_PATH =
41+
".mvn/wrapper/maven-wrapper.jar";
42+
43+
/**
44+
* Name of the property which should be used to override the default download url for the wrapper.
45+
*/
46+
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
47+
48+
public static void main(String args[]) {
49+
System.out.println("- Downloader started");
50+
File baseDirectory = new File(args[0]);
51+
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
52+
53+
// If the maven-wrapper.properties exists, read it and check if it contains a custom
54+
// wrapperUrl parameter.
55+
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
56+
String url = DEFAULT_DOWNLOAD_URL;
57+
if(mavenWrapperPropertyFile.exists()) {
58+
FileInputStream mavenWrapperPropertyFileInputStream = null;
59+
try {
60+
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
61+
Properties mavenWrapperProperties = new Properties();
62+
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
63+
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
64+
} catch (IOException e) {
65+
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
66+
} finally {
67+
try {
68+
if(mavenWrapperPropertyFileInputStream != null) {
69+
mavenWrapperPropertyFileInputStream.close();
70+
}
71+
} catch (IOException e) {
72+
// Ignore ...
73+
}
74+
}
75+
}
76+
System.out.println("- Downloading from: " + url);
77+
78+
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
79+
if(!outputFile.getParentFile().exists()) {
80+
if(!outputFile.getParentFile().mkdirs()) {
81+
System.out.println(
82+
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
83+
}
84+
}
85+
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
86+
try {
87+
downloadFileFromURL(url, outputFile);
88+
System.out.println("Done");
89+
System.exit(0);
90+
} catch (Throwable e) {
91+
System.out.println("- Error downloading");
92+
e.printStackTrace();
93+
System.exit(1);
94+
}
95+
}
96+
97+
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
98+
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
99+
String username = System.getenv("MVNW_USERNAME");
100+
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
101+
Authenticator.setDefault(new Authenticator() {
102+
@Override
103+
protected PasswordAuthentication getPasswordAuthentication() {
104+
return new PasswordAuthentication(username, password);
105+
}
106+
});
107+
}
108+
URL website = new URL(urlString);
109+
ReadableByteChannel rbc;
110+
rbc = Channels.newChannel(website.openStream());
111+
FileOutputStream fos = new FileOutputStream(destination);
112+
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
113+
fos.close();
114+
rbc.close();
115+
}
116+
117+
}
Binary file not shown.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.1/apache-maven-3.8.1-bin.zip
2+
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>quarkus-registry-kafka-quickstart</artifactId>
7+
<groupId>org.example</groupId>
8+
<version>1.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>quarkus-registry-kafka-quickstart-producer</artifactId>
13+
14+
<properties>
15+
<surefire-plugin.version>3.0.0-M5</surefire-plugin.version>
16+
<quarkus-plugin.version>2.2.3.Final</quarkus-plugin.version>
17+
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
18+
<quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
19+
<quarkus.platform.version>2.2.3.Final</quarkus.platform.version>
20+
<maven.compiler.source>11</maven.compiler.source>
21+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
22+
<maven.compiler.target>11</maven.compiler.target>
23+
<testcontainers.version>1.15.2</testcontainers.version>
24+
</properties>
25+
<dependencyManagement>
26+
<dependencies>
27+
<dependency>
28+
<groupId>${quarkus.platform.group-id}</groupId>
29+
<artifactId>${quarkus.platform.artifact-id}</artifactId>
30+
<version>${quarkus.platform.version}</version>
31+
<type>pom</type>
32+
<scope>import</scope>
33+
</dependency>
34+
</dependencies>
35+
</dependencyManagement>
36+
<dependencies>
37+
<dependency>
38+
<groupId>io.quarkus</groupId>
39+
<artifactId>quarkus-smallrye-reactive-messaging-kafka</artifactId>
40+
</dependency>
41+
<dependency>
42+
<groupId>io.quarkus</groupId>
43+
<artifactId>quarkus-resteasy-reactive</artifactId>
44+
</dependency>
45+
<dependency>
46+
<groupId>io.quarkus</groupId>
47+
<artifactId>quarkus-apicurio-registry-avro</artifactId>
48+
</dependency>
49+
<dependency>
50+
<groupId>io.quarkus</groupId>
51+
<artifactId>quarkus-arc</artifactId>
52+
</dependency>
53+
<dependency>
54+
<groupId>io.quarkus</groupId>
55+
<artifactId>quarkus-smallrye-health</artifactId>
56+
</dependency>
57+
<dependency>
58+
<groupId>io.strimzi</groupId>
59+
<artifactId>kafka-oauth-client</artifactId>
60+
<version>0.8.1</version>
61+
</dependency>
62+
<dependency>
63+
<groupId>io.quarkus</groupId>
64+
<artifactId>quarkus-junit5</artifactId>
65+
<scope>test</scope>
66+
</dependency>
67+
<dependency>
68+
<groupId>org.jboss.resteasy</groupId>
69+
<artifactId>resteasy-client</artifactId>
70+
<scope>test</scope>
71+
</dependency>
72+
<dependency>
73+
<groupId>io.rest-assured</groupId>
74+
<artifactId>rest-assured</artifactId>
75+
<scope>test</scope>
76+
</dependency>
77+
</dependencies>
78+
<build>
79+
<plugins>
80+
<plugin>
81+
<groupId>io.quarkus</groupId>
82+
<artifactId>quarkus-maven-plugin</artifactId>
83+
<version>${quarkus-plugin.version}</version>
84+
<executions>
85+
<execution>
86+
<goals>
87+
<goal>build</goal>
88+
<goal>generate-code</goal>
89+
<goal>generate-code-tests</goal>
90+
</goals>
91+
</execution>
92+
</executions>
93+
</plugin>
94+
<plugin>
95+
<artifactId>maven-surefire-plugin</artifactId>
96+
<version>${surefire-plugin.version}</version>
97+
<configuration>
98+
<systemPropertyVariables>
99+
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
100+
<maven.home>${maven.home}</maven.home>
101+
</systemPropertyVariables>
102+
</configuration>
103+
</plugin>
104+
</plugins>
105+
</build>
106+
<profiles>
107+
<profile>
108+
<id>native</id>
109+
<activation>
110+
<property>
111+
<name>native</name>
112+
</property>
113+
</activation>
114+
<properties>
115+
<quarkus.package.type>native</quarkus.package.type>
116+
</properties>
117+
<build>
118+
<plugins>
119+
<plugin>
120+
<artifactId>maven-failsafe-plugin</artifactId>
121+
<version>${surefire-plugin.version}</version>
122+
<executions>
123+
<execution>
124+
<goals>
125+
<goal>integration-test</goal>
126+
<goal>verify</goal>
127+
</goals>
128+
<configuration>
129+
<systemPropertyVariables>
130+
<native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
131+
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
132+
<maven.home>${maven.home}</maven.home>
133+
</systemPropertyVariables>
134+
</configuration>
135+
</execution>
136+
</executions>
137+
</plugin>
138+
</plugins>
139+
</build>
140+
</profile>
141+
</profiles>
142+
143+
</project>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"namespace": "org.acme.kafka.quarkus",
3+
"type": "record",
4+
"name": "Quote",
5+
"fields": [
6+
{
7+
"name": "id",
8+
"type": "string"
9+
},
10+
{
11+
"name": "price",
12+
"type": "int"
13+
}
14+
]
15+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.acme.kafka.consumer;
2+
3+
4+
import javax.ws.rs.GET;
5+
import javax.ws.rs.Path;
6+
import javax.ws.rs.Produces;
7+
import javax.ws.rs.core.MediaType;
8+
9+
import org.acme.kafka.quarkus.Quote;
10+
import org.eclipse.microprofile.reactive.messaging.Channel;
11+
12+
import io.smallrye.mutiny.Multi;
13+
import org.jboss.resteasy.reactive.RestSseElementType;
14+
15+
@Path("/quotes")
16+
public class QuotesResource {
17+
18+
@Channel("quotes")
19+
Multi<Quote> quotes;
20+
21+
/**
22+
* Endpoint retrieving the "quotes" Kafka topic and sending the items to a server sent event.
23+
*/
24+
@GET
25+
@Produces(MediaType.SERVER_SENT_EVENTS) // denotes that server side events (SSE) will be produced
26+
@RestSseElementType(MediaType.TEXT_PLAIN)
27+
public Multi<Quote> stream() {
28+
return quotes.log();
29+
}
30+
}
31+

0 commit comments

Comments
 (0)