-
Notifications
You must be signed in to change notification settings - Fork 21
/
Routing.java
executable file
·46 lines (34 loc) · 1.17 KB
/
Routing.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
// camel-k: language=java
import java.util.Random;
import org.apache.camel.PropertyInject;
import org.apache.camel.builder.RouteBuilder;
public class Routing extends RouteBuilder {
private final Random random = new Random();
@PropertyInject("priority-marker")
private String priorityMarker;
@Override
public void configure() throws Exception {
from("timer:java?period=3000")
.id("generator")
.bean(this, "generateRandomItem({{items}})")
.choice()
.when().simple("${body.startsWith('{{priority-marker}}')}")
.transform().body(String.class, item -> item.substring(priorityMarker.length()))
.to("direct:priorityQueue")
.otherwise()
.to("direct:standardQueue");
from("direct:standardQueue")
.id("standard")
.log("Standard item: ${body}");
from("direct:priorityQueue")
.id("priority")
.log("!!Priority item: ${body}");
}
public String generateRandomItem(String items) {
if (items == null || items.equals("")) {
return "[no items configured]";
}
String[] list = items.split("\\s");
return list[random.nextInt(list.length)];
}
}