Created
January 16, 2020 17:34
-
-
Save cvicens/f9f9239ed9b805e053fb6e28f269e193 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import ... | |
public class EventsToTelegramBot extends RouteBuilder { | |
@Override | |
public void configure() throws Exception { | |
from("kafka:{{kafka.from.topic}}?brokers={{kafka.bootstrap-servers}}&groupId={{kafka.groupId}}") | |
.routeId("events-to-bot") | |
.onException(Exception.class) | |
.handled(true) | |
.log(LoggingLevel.ERROR, "Error connecting to server, please check the application.properties file ${exception.message}") | |
.end() | |
.log("Route started from Kafka Topic {{kafka.from.topic}}") | |
.log("body: ${body}") | |
.log("Sending message to telegram bot http://{{telegram-bot.host}}:{{telegram-bot.port}}/new-message: ${body}") | |
.to("direct:send-event-to-bot") | |
.log("Event sent successfully: ${body}"); | |
from("direct:send-event-to-bot") | |
.routeId("send-event-to-bot") | |
.setHeader("id", header(Exchange.TIMER_COUNTER)) | |
.setHeader(Exchange.HTTP_METHOD, constant("POST")) | |
.setHeader(Exchange.CONTENT_TYPE, constant("application/json")) | |
.setHeader(Exchange.HTTP_CHARACTER_ENCODING, constant("UTF-8")) | |
.log("Executing saga #${headers} ${body}") | |
.to("http://{{telegram-bot.host}}:{{telegram-bot.port}}/new-message") | |
.log("Patient info sent successfully: ${body}"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment