diff --git a/README.md b/README.md index 87c79bb..946e4c2 100644 --- a/README.md +++ b/README.md @@ -6,9 +6,8 @@ [![Quarkus](https://img.shields.io/badge/quarkus-4695EB?logo=quarkus&logoColor=white)](https://quarkus.io/) [![Docker](https://img.shields.io/badge/docker-2496ED?logo=docker&logoColor=white)](https://www.docker.com/) -A small university project to discover the [Quarkus Framework](https://quarkus.io/) to build the -application combined with the [Kafka platform](https://kafka.apache.org/), the whole compatible -with [Docker](https://www.docker.com/). +A small university project to discover the [Quarkus Framework](https://quarkus.io/) combined with the +[Kafka library](https://kafka.apache.org/), the whole compatible with [Docker](https://www.docker.com/). ## Run You can run the project very simply with either [Intellij IDEA](https://www.jetbrains.com/idea/), @@ -37,8 +36,8 @@ The container `application` can be easily modified with the following environmen |------------------------------|----------|-----------------------------------------------------|--------------------------------------------------------------------|---------------------------------------------------------------| | KAFKA_BOOTSTRAP_SERVERS | true | \[:port] | / | The Kafka server address | | TOPIC_TEMPERATURE_CELSIUS | false | string of alphanumeric characters, ".", "_" and "-" | temperature-celsius | The name of the Kafka topic for the temperature in Celsius | -| TOPIC_TEMPERATURE_FAHRENHEIT | false | string of alphanumeric characters, ".", "_" and "-" | temperature-fahrenheit | The name of the Kafka topic for the temperature in Fahrenheit | | -| TEMPERATURE_LOCATION | true | \, \ | 49.9, 2.3 ([Amiens, France](https://fr.wikipedia.org/wiki/Amiens)) | The coordinates where to get the temperatures from | +| TOPIC_TEMPERATURE_FAHRENHEIT | false | string of alphanumeric characters, ".", "_" and "-" | temperature-fahrenheit | The name of the Kafka topic for the temperature in Fahrenheit | +| TEMPERATURE_LOCATION | true | \, \ | 49.9, 2.3 ([Amiens, France](https://fr.wikipedia.org/wiki/Amiens)) | The coordinates where to get the temperatures from | ## Expectation The `application` container shall print the current temperature at the selected place in diff --git a/src/main/kotlin/fr/faraphel/m1_pe_kafka/Main.kt b/src/main/kotlin/fr/faraphel/m1_pe_kafka/Main.kt index 8bed7f0..2492e67 100644 --- a/src/main/kotlin/fr/faraphel/m1_pe_kafka/Main.kt +++ b/src/main/kotlin/fr/faraphel/m1_pe_kafka/Main.kt @@ -1,5 +1,6 @@ package fr.faraphel.m1_pe_kafka +import fr.faraphel.m1_pe_kafka.error.MissingEnvironmentException import fr.faraphel.m1_pe_kafka.kafka.AdminUtils import fr.faraphel.m1_pe_kafka.kafka.PrintConsumer import fr.faraphel.m1_pe_kafka.kafka.Converter @@ -20,11 +21,12 @@ class Main : QuarkusApplication { * The entrypoint of the program * @param args command line arguments * @return the result code of the program + * @throws MissingEnvironmentException a required environment variable from the configuration is missing */ override fun run(vararg args: String?): Int { // get the kafka server address val kafkaServer = System.getenv("KAFKA_BOOTSTRAP_SERVERS") - ?: throw IllegalArgumentException("Missing environment variable: KAFKA_BOOTSTRAP_SERVERS") + ?: throw MissingEnvironmentException("KAFKA_BOOTSTRAP_SERVERS") // get the topics name val topicTemperatureCelsius: String = System.getenv("TOPIC_TEMPERATURE_CELSIUS") @@ -39,7 +41,7 @@ class Main : QuarkusApplication { // get the location of the temperature to get val location = System.getenv("TEMPERATURE_LOCATION") - ?: throw IllegalArgumentException("Missing environment variable: TEMPERATURE_LOCATION") + ?: throw MissingEnvironmentException("TEMPERATURE_LOCATION") // parse the location to get the latitude and longitude val (latitude, longitude) = location.split(",").map { coordinate -> coordinate.trim().toDouble() } diff --git a/src/main/kotlin/fr/faraphel/m1_pe_kafka/error/MissingEnvironmentException.kt b/src/main/kotlin/fr/faraphel/m1_pe_kafka/error/MissingEnvironmentException.kt new file mode 100644 index 0000000..9ea00a1 --- /dev/null +++ b/src/main/kotlin/fr/faraphel/m1_pe_kafka/error/MissingEnvironmentException.kt @@ -0,0 +1,8 @@ +package fr.faraphel.m1_pe_kafka.error + + +/** + * An exception raised if a required environment variable is missing + */ +class MissingEnvironmentException(message: String) + : IllegalArgumentException("Missing required environment variable: $message") diff --git a/src/main/kotlin/fr/faraphel/m1_pe_kafka/kafka/AdminUtils.kt b/src/main/kotlin/fr/faraphel/m1_pe_kafka/kafka/AdminUtils.kt index e4321ea..748013e 100644 --- a/src/main/kotlin/fr/faraphel/m1_pe_kafka/kafka/AdminUtils.kt +++ b/src/main/kotlin/fr/faraphel/m1_pe_kafka/kafka/AdminUtils.kt @@ -9,7 +9,6 @@ import java.util.* /** * A wrapper around KafkaAdminClient to simplify its configuration. - * @throws IllegalArgumentException the environment variables are not properly set. * @param server the kafka server address * @param identifier the kafka identifier for the configuration * @see Admin diff --git a/src/main/kotlin/fr/faraphel/m1_pe_kafka/kafka/PrintConsumer.kt b/src/main/kotlin/fr/faraphel/m1_pe_kafka/kafka/PrintConsumer.kt index 7e956e3..912501d 100644 --- a/src/main/kotlin/fr/faraphel/m1_pe_kafka/kafka/PrintConsumer.kt +++ b/src/main/kotlin/fr/faraphel/m1_pe_kafka/kafka/PrintConsumer.kt @@ -22,7 +22,6 @@ import kotlin.time.toJavaDuration * @param server the kafka server address * @param topic the topic to get the records from * @param identifier the kafka identifier for the configuration - * @throws IllegalArgumentException the environment variables are not properly set. */ class PrintConsumer( private val server: String,