-
Notifications
You must be signed in to change notification settings - Fork 30
/
HealthBridge.java
58 lines (44 loc) · 2.31 KB
/
HealthBridge.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// camel-k: language=java property=file:application.properties
// camel-k: dependency=mvn:org.amqphub.quarkus:quarkus-qpid-jms
// camel-k: dependency=github:openshift-integration:camel-k-example-event-streaming
import org.apache.camel.builder.RouteBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.camel.model.dataformat.JsonLibrary;
import com.redhat.integration.common.Alert;
import com.redhat.integration.common.Data;
public class HealthBridge extends RouteBuilder {
private static final Logger LOG = LoggerFactory.getLogger(HealthBridge.class);
final String unsafeHeader = "unsafe";
final String locationHeader = "location";
public void configure() throws Exception {
from("kafka:health-data?brokers={{kafka.bootstrap.address}}&groupId=healthbrige&autoOffsetReset=earliest")
.unmarshal().json(JsonLibrary.Jackson, Data.class)
.process(exchange -> {
Data eventData = exchange.getMessage().getBody(Data.class);
Alert alert = new Alert();
if (eventData.getReport().isAlert()) {
exchange.getMessage().setHeader(unsafeHeader, true);
alert.setSeverity("red");
} else {
alert.setSeverity("yellow");
}
String text = String.format("There is a %s incident on %s", eventData.getReport().getMeasurement(),
eventData.getReport().getLocation());
alert.setText(text);
exchange.getMessage().setBody(alert);
exchange.getMessage().setHeader(locationHeader, eventData.getReport().getLocation());
})
.marshal().json()
.convertBodyTo(String.class)
.wireTap("direct:timeline")
.choice()
.when(header(unsafeHeader).isEqualTo(true))
.to("jms://queue:alarms?timeToLive={{messaging.ttl.alarms}}")
.otherwise()
.to("jms://queue:notifications?timeToLive={{messaging.ttl.notifications}}");
from("direct:timeline")
.log("${body}")
.to("kafka:timeline-data?brokers={{kafka.bootstrap.address}}");
}
}