This is a simple integration I used with springboot, camel, kafka. I had to consume from a topic and do some logic to produce on another topic. I followed the same idea to develop a "topic switcher" that chose on what topic to produce (not in this post but the solution is immediate).
The routebuilder is the main camel class that call "getBody" method on a bean that do the magic. The bean call back the routebuilder to produce on Kafka.
//ROUTEBUILDER:
@Component
public class MyRouteBuilder extends RouteBuilder {
@Override
public void configure() throws Exception {
from("kafka:{{consumer.topic}}?brokers={{kafka.brokers}}&consumersCount={{consumer.consumersCount}}&groupId={{consumer.group}}")
.routeId("FromKafka")
.log("------- ROUTE BUILDER -------")
.onException(Exception.class)
.log(LoggingLevel.ERROR, "crash-data-stream", "Invalid Input")
.maximumRedeliveries(2).redeliveryDelay(30000)
.end()
.to("bean:externalBean?method=getBody(${body})");
from("direct:myproducer")
.routeId("myproducer")
.to("kafka:{{producer.topic}}?brokers={{kafka.brokers}}")
;
}
}
----------------------------------
//EXTERNAL BEAN
@Service
public class ExternalBean {
@EndpointInject("direct:myproducer")
ProducerTemplate producer;
public void getBody(String body) throws Exception {
//do stuff and send back to camel
myproducer.sendBody(body);
}
}
venerdì 27 marzo 2020
lunedì 2 marzo 2020
Spring boot multiple property files
Add in pom:
<build>
...
<resources>
<resource>
<directory>src/main/resources< /directory>
<filtering>true</filtering>
</resource>
</resources>
...
</build>
-
Add
<plugin>
<groupId>org.apache.maven. plugins</groupId>
<artifactId>maven-help-plugin< /artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>show-profiles</id>
<phase>compile</phase>
<goals>
<goal>active-profiles</goal>
</goals>
</execution>
</executions>
</plugin>
-
Add
<profiles>
<profile>
<id>dev</id>
<properties>
<activatedProperties>dev</ activatedProperties>
</properties>
<activation>
<activeByDefault>true</ activeByDefault>
</activation>
</profile>
<profile>
<id>prod</id>
<properties>
<activatedProperties>prod</ activatedProperties>
</properties>
</profile>
</profiles>
-
Create application.properties:
spring.profiles.active=@ activatedProperties@
-
Create:
application-dev.properties
application-prod.properties
-
run:
mvn clean spring-boot:run -Pprod
//or
mvn clean spring-boot:run -Dspring-boot.run.profiles=dev
Iscriviti a:
Post (Atom)
How to deploy Podman images to OpenShift Container Platform (CRC on localhost)
I have a microservice on localhost and I want to deploy its Podman image on OCP, which I am running using CRC on localhost. 1. Get the...
-
Precondizione: La precondizione di un metodo e' una condizione che deve essere verificata prima che quel metodo sia invocato. Le preco...
-
My intent is to configure SSO on Keycloak and Liferay. I have createad a docker-compose environment with Keycloak: #####################...