-
Notifications
You must be signed in to change notification settings - Fork 1
/
ContentBasedRouter.java
31 lines (27 loc) · 1.22 KB
/
ContentBasedRouter.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
// camel-k: language=java
import org.apache.camel.builder.RouteBuilder;
import static org.apache.camel.builder.PredicateBuilder.*;
public class ContentBasedRouter extends RouteBuilder {
@Override
public void configure() throws Exception {
String location = "Everest";
String message = "Today's weather in " + location + " is: ";
from("quartz:router?trigger.repeatInterval={{quartz.repeatInterval:60000}}")
.routeId("content-based-router")
.toF("https://wttr.in/~%s?format=j1", location)
.transform().jsonpath("$.current_condition[0].weatherDesc[0].value").choice()
.when(or(body().contains("Sunny"), body().contains("Clear")))
.transform().constant(message + "☀")
.endChoice()
.when(or(body().contains("Cloudy"), body().contains("cloudy"), body().contains("Overcast")))
.transform().constant(message + "☁")
.endChoice()
.when(body().contains("rain"))
.transform().constant(message + "☂")
.endChoice()
.otherwise()
.transform().simple(message + "${body}")
.end()
.to("stream:out");
}
}