From 1908c4d7d166780d16afd559ba0b4df528c8b9bd Mon Sep 17 00:00:00 2001 From: Christopher Moyer Date: Wed, 4 Jan 2023 21:51:11 -0500 Subject: [PATCH] updated for native --- pom.xml | 2 +- .../com/c4181/camel/CamelConfiguration.java | 27 ++++++++++++------- .../com/c4181/properties/AppProperties.java | 10 +++++++ src/main/resources/application.properties | 5 ++++ 4 files changed, 33 insertions(+), 11 deletions(-) create mode 100644 src/main/java/com/c4181/properties/AppProperties.java diff --git a/pom.xml b/pom.xml index 03b433a..8ff998f 100644 --- a/pom.xml +++ b/pom.xml @@ -134,7 +134,7 @@ false - uber-jar + native diff --git a/src/main/java/com/c4181/camel/CamelConfiguration.java b/src/main/java/com/c4181/camel/CamelConfiguration.java index 3915a00..1553135 100644 --- a/src/main/java/com/c4181/camel/CamelConfiguration.java +++ b/src/main/java/com/c4181/camel/CamelConfiguration.java @@ -1,19 +1,26 @@ package com.c4181.camel; +import com.c4181.properties.AppProperties; import org.apache.camel.Exchange; import org.apache.camel.builder.RouteBuilder; import org.apache.commons.lang3.StringUtils; +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Inject; import javax.measure.Measure; import javax.measure.quantity.Pressure; import javax.measure.unit.NonSI; import javax.measure.unit.Unit; +@ApplicationScoped public class CamelConfiguration extends RouteBuilder { + @Inject + AppProperties appProperties; + @Override public void configure() { - from("paho-mqtt5:teslamate/cars/1/update_version?brokerUrl={{sys:BROKER_URL}}") + from("paho-mqtt5:teslamate/cars/1/update_version?brokerUrl=" + appProperties.brokerUrl()) .filter(exchange -> StringUtils.isNotBlank(exchange.getIn().getBody(String.class))) .process((exchange -> { String updateVersion = exchange.getIn().getBody(String.class); @@ -26,27 +33,27 @@ public class CamelConfiguration extends RouteBuilder { log.info("New Version {} found. Sending to telegram", updateVersion); })) - .to("telegram:bots?authorizationToken={{sys:TELEGRAM_BOT_ID}}&chatId={{sys:CHAT_ID}}"); + .to(appProperties.telegramRoute()); - from("paho-mqtt5:teslamate/cars/1/tpms_pressure_fl?brokerUrl={{sys:BROKER_URL}}").process((exchange -> checkTirePressure(exchange, "Front left"))) + from("paho-mqtt5:teslamate/cars/1/tpms_pressure_fl?brokerUrl=" + appProperties.brokerUrl()).process((exchange -> checkTirePressure(exchange, "Front left"))) .throttle(1).rejectExecution(true) .timePeriodMillis(900000) // 15 minutes - .to("telegram:bots?authorizationToken={{sys:TELEGRAM_BOT_ID}}&chatId={{sys:CHAT_ID}}"); + .to(appProperties.telegramRoute()); - from("paho-mqtt5:teslamate/cars/1/tpms_pressure_fr?brokerUrl={{sys:BROKER_URL}}").process((exchange -> checkTirePressure(exchange, "Front right"))) + from("paho-mqtt5:teslamate/cars/1/tpms_pressure_fr?brokerUrl=" + appProperties.brokerUrl()).process((exchange -> checkTirePressure(exchange, "Front right"))) .throttle(1).rejectExecution(true) .timePeriodMillis(900000) // 15 minutes - .to("telegram:bots?authorizationToken={{sys:TELEGRAM_BOT_ID}}&chatId={{sys:CHAT_ID}}"); + .to(appProperties.telegramRoute()); - from("paho-mqtt5:teslamate/cars/1/tpms_pressure_rl?brokerUrl={{sys:BROKER_URL}}").process((exchange -> checkTirePressure(exchange, "Back left"))) + from("paho-mqtt5:teslamate/cars/1/tpms_pressure_rl?brokerUrl=" + appProperties.brokerUrl()).process((exchange -> checkTirePressure(exchange, "Back left"))) .throttle(1).rejectExecution(true) .timePeriodMillis(900000) // 15 minutes - .to("telegram:bots?authorizationToken={{sys:TELEGRAM_BOT_ID}}&chatId={{sys:CHAT_ID}}"); + .to(appProperties.telegramRoute()); - from("paho-mqtt5:teslamate/cars/1/tpms_pressure_rr?brokerUrl={{sys:BROKER_URL}}").process((exchange -> checkTirePressure(exchange, "Back right"))) + from("paho-mqtt5:teslamate/cars/1/tpms_pressure_rr?brokerUrl=" + appProperties.brokerUrl()).process((exchange -> checkTirePressure(exchange, "Back right"))) .throttle(1).rejectExecution(true) .timePeriodMillis(900000) // 15 minutes - .to("telegram:bots?authorizationToken={{sys:TELEGRAM_BOT_ID}}&chatId={{sys:CHAT_ID}}"); + .to(appProperties.telegramRoute()); } private void checkTirePressure(Exchange exchange, String tire) { diff --git a/src/main/java/com/c4181/properties/AppProperties.java b/src/main/java/com/c4181/properties/AppProperties.java new file mode 100644 index 0000000..b58bad7 --- /dev/null +++ b/src/main/java/com/c4181/properties/AppProperties.java @@ -0,0 +1,10 @@ +package com.c4181.properties; + +import io.smallrye.config.ConfigMapping; + +@ConfigMapping(prefix = "app") +public interface AppProperties { + + String brokerUrl(); + String telegramRoute(); +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index e69de29..8b9f194 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -0,0 +1,5 @@ +app.broker-url=${BROKER_URL} +app.telegram-route=telegram:bots?authorizationToken=${TELEGRAM_BOT_ID}&chatId=${CHAT_ID} + +TELEGRAM_BOT_ID=${TELEGRAM_BOT_ID} +CHAT_ID=${CHAT_ID} \ No newline at end of file