-
Notifications
You must be signed in to change notification settings - Fork 16
/
CautiousInvestorAdapterSink.java
executable file
·39 lines (31 loc) · 1.24 KB
/
CautiousInvestorAdapterSink.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
// camel-k: language=java
import org.apache.camel.Exchange;
import org.apache.camel.builder.RouteBuilder;
public class CautiousInvestorAdapterSink extends RouteBuilder {
@Override
public void configure() throws Exception {
from("knative:event/predictor.better")
.removeHeaders("*")
.unmarshal().json()
.log("Received prediction to ${body[operation]} BTC")
.choice()
.when().simple("${body[operation]} == 'buy'")
.to("seda:buy?waitForTaskToComplete=Never")
.when().simple("${body[operation]} == 'sell'")
.to("seda:sell?waitForTaskToComplete=Never")
.otherwise()
.log("Unsupported operation: ${body[operation]}")
.end()
.setBody().constant("");
from("seda:buy")
.log("Informing the external service to BUY...")
.setHeader(Exchange.HTTP_METHOD, constant("POST"))
.marshal().json()
.to("http://cautious-investor-service.{{env:NAMESPACE}}.svc.cluster.local/BTC");
from("seda:sell")
.log("Informing the external service to SELL...")
.setHeader(Exchange.HTTP_METHOD, constant("DELETE"))
.marshal().json()
.to("http://cautious-investor-service.{{env:NAMESPACE}}.svc.cluster.local/BTC");
}
}