8.2. 实施示例 Camel Quarkus 应用程序
在本例中,将实施简单的 Camel 'hello-world' Quarkus 应用。使用以下内容将
src/main/java/org/hawtio/SampleCamelRoute.java文件添加到项目中:package org.hawtio; import jakarta.enterprise.context.ApplicationScoped; import org.apache.camel.builder.endpoint.EndpointRouteBuilder; @ApplicationScoped public class SampleCamelRoute extends EndpointRouteBuilder { @Override public void configure() { from(quartz("cron").cron("{{quartz.cron}}")).routeId("cron") .setBody().constant("Hello Camel! - cron") .to(stream("out")) .to(mock("result")); from("quartz:simple?trigger.repeatInterval={{quartz.repeatInterval}}").routeId("simple") .setBody().constant("Hello Camel! - simple") .to(stream("out")) .to(mock("result")); } }- 这个示例通过 Camel 路由在容器日志中记录 "Hello Camel …" 条目。
使用以下属性修改
src/main/resources/application.properties文件:# Camel camel.context.name = SampleCamel # Uncomment the following to enable the Camel plugin Trace tab #camel.main.tracing = true #camel.main.backlogTracing = true #camel.main.useBreadcrumb = true # Uncomment to enable debugging of the application and in turn # enables the Camel plugin Debug tab even in non-development # environment #quarkus.camel.debug.enabled = true # Define properties for the Camel quartz component used in the # example quartz.cron = 0/10 * * * * ? quartz.repeatInterval = 10000将以下依赖项添加到文件
pom.xml的 <dependencies> 部分。由于src/main/java/org/hawtio/SampleCamelRoute.java中定义的路由需要这些;如果添加到应用程序的 Camel 路由发生了变化,则需要修改它们:<dependency> <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-stream</artifactId> </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-mock</artifactId> </dependency>