-
Notifications
You must be signed in to change notification settings - Fork 0
/
CrimeBridge.java
56 lines (44 loc) · 2.34 KB
/
CrimeBridge.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
// camel-k: language=java property=file:application.properties
// camel-k: dependency=mvn:org.amqphub.quarkus:quarkus-qpid-jms dependency=github:openshift-integration:camel-k-example-event-streaming:1.6.x-SNAPSHOT
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 CrimeBridge extends RouteBuilder {
private static final Logger LOG = LoggerFactory.getLogger(CrimeBridge.class);
public void configure() throws Exception {
final String unsafeHeader = "unsafe";
final String locationHeader = "location";
from("kafka:crime-data?brokers={{kafka.bootstrap.address}}&groupId=crimebrige&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}}");
}
}