2.6. Java DSL 路由迁移示例
要将 Java DSL 路由定义从 Fuse 应用程序迁移到 CSB,您可以将现有路由定义直接复制到 CSB 应用,并将必要的依赖项添加到应用程序的 pom.xml 文件中。
在本例中,我们将通过将 Java DSL 路由复制到您的 CSB 应用中的名为 MyCamelRouter.java 的文件,将基于内容的路由从 Fuse 7 应用迁移到新的 CSB 应用。
流程
- 下载 Spring Boot 示例。本例演示了如何使用 Spring Boot 使用简单的 Apache Camel 应用程序。
进入从上一步中提取示例文件的目录:
$ cd <directory_name>-
在
src/main/java/sample/camel/subfolder 中查找名为MyCamelRouter.java的文件。 将 Fuse 应用程序的路由定义添加到
MyCamelRouter.java,如下例所示:package sample.camel; import org.apache.camel.builder.RouteBuilder; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; /** * A simple Camel route that triggers from a timer and calls a bean and prints to system out. * <p/> * Use <tt>@Component</tt> to make Camel auto-detect this route when starting. */ @Component public class MyCamelRouter extends RouteBuilder { // we can use spring dependency injection @Autowired MyBean myBean; @Override public void configure() throws Exception { // start from a timer from("timer:hello?period={{myPeriod}}").routeId("hello") // and call the bean .bean(myBean, "saySomething") // and print it to system out via stream component .to("stream:out"); } }运行您的 CSB 应用程序。
mvn spring-boot:run