Skip to content

Commit

Permalink
Adding example Kafka consumer/producer route from Apache examples
Browse files Browse the repository at this point in the history
  • Loading branch information
mike4263 committed May 30, 2024
1 parent 233670d commit 1c5c675
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 1 deletion.
14 changes: 13 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<properties>
<compiler-plugin.version>3.12.1</compiler-plugin.version>
<maven.compiler.release>21</maven.compiler.release>
<maven.compiler.release>17</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
Expand Down Expand Up @@ -53,6 +53,18 @@
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-netty</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-log</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-timer</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-seda</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc</artifactId>
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/com/redhat/naps/launch/Application.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.redhat.naps.launch;

import jakarta.enterprise.context.ApplicationScoped;
import org.apache.camel.builder.RouteBuilder;

@ApplicationScoped
public class Application extends RouteBuilder {
@Override
public void configure() throws Exception {
// produces messages to kafka
from("timer:foo?period={{timer.period}}&delay={{timer.delay}}")
.routeId("FromTimer2Kafka")
.setBody().simple("Message #${exchangeProperty.CamelTimerCounter}")
.to("kafka:{{kafka.topic.name}}")
.log("Message correctly sent to the topic! : \"${body}\" ");

// kafka consumer
from("kafka:{{kafka.topic.name}}")
.routeId("FromKafka2Seda")
.log("Received : \"${body}\"")
.to("seda:kafka-messages");
}
}
81 changes: 81 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@

# Use Strimzi as it's power architecture compatible
quarkus.kafka.devservices.provider = strimzi

# Kafka topic Name
kafka.topic.name=test

# Kafka brokers in native test
%prod.camel.component.kafka.brokers=${kafka.bootstrap.servers}

# How often should the messages be generated and pushed to Kafka Topic
timer.period = 10000
timer.delay = 10000

# Kafka instance without Authentication
#camel.component.kafka.brokers=${brokers}

# uncomment to set Kafka instance with SASL Plain
#camel.component.kafka.brokers=${brokers}
#camel.component.kafka.security-protocol=SASL_SSL
#camel.component.kafka.sasl-mechanism=PLAIN
#camel.component.kafka.sasl-jaas-config=org.apache.kafka.common.security.plain.PlainLoginModule required username="${id}" password="${secret}";

# uncomment to set Kafka instance with SASL Oauth Bearer
#camel.component.kafka.brokers = ${brokers}
#camel.component.kafka.security-protocol = SASL_SSL
#camel.component.kafka.sasl-mechanism = OAUTHBEARER
#camel.component.kafka.sasl-jaas-config = org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginModule required \
# oauth.client.id="${id}" \
# oauth.client.secret="${secret}" \
# oauth.token.endpoint.uri="${token}" ;
#camel.component.kafka.additional-properties[sasl.login.callback.handler.class] = io.strimzi.kafka.oauth.client.JaasClientOauthLoginCallbackHandler


###################################
# Kubernetes specific
###################################
# secrets
#quarkus.kubernetes-config.enabled=true
#getting secrets while deploying to kubernetes
#quarkus.kubernetes-config.namespace=test
#quarkus.kubernetes-config.secrets.enabled=true
#quarkus.kubernetes-config.secrets=camel-kafka

# creating container with jib
#quarkus.container-image.build=true
#quarkus.kubernetes.deployment-target=kubernetes
#quarkus.container-image.group=<YOUR_IMAGE_GROUP>
#quarkus.container-image.registry=<YOUR_REGISTRY_URL>

# Uncomment to trust self signed certificates if they are presented by the Kubernetes API server
#quarkus.kubernetes-client.trust-certs=true

# Uncomment to set resource limits
#quarkus.kubernetes.resources.requests.memory=64Mi
#quarkus.kubernetes.resources.requests.cpu=250m
#quarkus.kubernetes.resources.limits.memory=512Mi
#quarkus.kubernetes.resources.limits.cpu=1000m

###################################
# OpenShift specific
###################################
# secrets
#quarkus.kubernetes-config.enabled=true
#getting secrets while deploying to kubernetes
#quarkus.kubernetes-config.namespace=test
#quarkus.kubernetes-config.secrets.enabled=true
#quarkus.kubernetes-config.secrets=camel-kafka

# creating container for openshift
#quarkus.container-image.build=true
#quarkus.kubernetes.deployment-target=openshift

# OpenShift
#quarkus.openshift.image-pull-policy=IfNotPresent

# Uncomment to set resource limits
#quarkus.openshift.resources.requests.memory=64Mi
#quarkus.openshift.resources.requests.cpu=250m
#quarkus.openshift.resources.limits.memory=512Mi
#quarkus.openshift.resources.limits.cpu=1000m

0 comments on commit 1c5c675

Please sign in to comment.