Implement Better Exception #10
5 changed files with 16 additions and 9 deletions
|
@ -6,9 +6,8 @@
|
|||
[](https://quarkus.io/)
|
||||
[](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 | \<ip>[: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 | \<latitude>, \<longitude> | 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 | \<latitude>, \<longitude> | 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
|
||||
|
|
|
@ -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() }
|
||||
|
|
|
@ -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")
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue