Skip to content

Instantly share code, notes, and snippets.

@cvicens
Created January 16, 2020 17:34
Show Gist options
  • Save cvicens/f9f9239ed9b805e053fb6e28f269e193 to your computer and use it in GitHub Desktop.
Save cvicens/f9f9239ed9b805e053fb6e28f269e193 to your computer and use it in GitHub Desktop.
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