This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//... | |
rest("/api").get("/hello").to("direct:hello"); | |
from("direct:hello").transform().constant("Hello world!"); | |
//... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//... | |
errorHandler(deadLetterChannel("kafka:dead_letter?brokers=localhost:9092") | |
.useOriginalMessage()); | |
//... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//... | |
from("timer://foo?period=5000").log("timer"); | |
//... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CamelRoutes extends EndpointRouteBuilder { | |
public void configure() { | |
from("kafka:input_topic?brokers=localhost:9092&groupId=group1") | |
.unmarshal().json(UserMessage.class) | |
.filter(simple("${body.type} == 'chat'")) | |
.to("seda:incoming_event"); | |
from("seda:incoming_event?multipleConsumers=true") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//... | |
from("kafka:input_topic?brokers=localhost:9092&groupId=group1") | |
.unmarshal().json(UserMessage.class) | |
.filter(simple("${body.type} == 'chat'")) | |
.log("${body}") | |
.split(simple("${body.devices}")) | |
.log("${body}") | |
.end() | |
.marshal().json() | |
.to("kafka:output_topic?brokers=localhost:9092") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from("kafka:input_topic?brokers=localhost:9092&groupId=group2") | |
.unmarshal().json(UserMessage.class) | |
.aggregate(simple("${body.emitter}"), new CombinedUserMessagesAggregationStrategy()) | |
.completionInterval(5000) | |
.bean(NLPUtils.class, "createUserMessages") | |
.log("${body}"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class NLPUtils { | |
public static UserMessages createUserMessages(final CombinedUserMessage event) { | |
return UserMessages.builder() | |
.emitter(event.getEmitter()) | |
.text(String.join(". ", event.getText())) | |
.build(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from("kafka:input_topic?brokers=localhost:9092&groupId=group2") | |
.unmarshal().json(UserMessage.class) | |
.aggregate(simple("${body.emitter}"), new CombinedUserMessagesAggregationStrategy()) | |
.completionInterval(5000) | |
.bean(NLPUtils.class, "createTranscription") | |
.log("${body}"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CombinedUserMessagesAggregationStrategy implements AggregationStrategy { | |
@Override | |
public Exchange aggregate(Exchange oldExchange, Exchange newExchange) { | |
if (oldExchange == null) { | |
final UserMessage body = newExchange.getIn().getBody(UserMessage.class); | |
final CombinedUserMessage newEventBody = CombinedUserMessage.builder() | |
.emitter(body.getEmitter()) | |
.text(List.of(body.getText())) | |
.build(); | |
newExchange.getIn().setBody(newEventBody); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//... | |
from("kafka:input_topic?brokers=localhost:9092&groupId=group2") | |
.unmarshal().json(UserMessage.class) | |
.aggregate(simple("${body.emitter}"), new CombinedUserMessagesAggregationStrategy()) | |
.completionInterval(5000) | |
.log("${body}"); | |
//... |