Add camel config #1

Merged
c4181 merged 4 commits from add-camel-config into main 2023-01-05 03:03:37 +00:00
4 changed files with 33 additions and 11 deletions
Showing only changes of commit 1908c4d7d1 - Show all commits

View file

@ -134,7 +134,7 @@
</activation>
<properties>
<skipITs>false</skipITs>
<quarkus.package.type>uber-jar</quarkus.package.type>
<quarkus.package.type>native</quarkus.package.type>
</properties>
</profile>
</profiles>

View file

@ -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) {

View file

@ -0,0 +1,10 @@
package com.c4181.properties;
import io.smallrye.config.ConfigMapping;
@ConfigMapping(prefix = "app")
public interface AppProperties {
String brokerUrl();
String telegramRoute();
}

View file

@ -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}