搜索

第 4 章 运行路由

download PDF

本教程介绍了运行路由的过程,以验证路由是否已正确将信息从源端点传输到接收器端点。

目标

在本教程中,您将完成以下任务:

  • 将路由作为本地 Camel 上下文运行(不带测试,因为您尚未设置测试)
  • 通过路由发送消息
  • 检查 sink 端点收到的消息,以确保路由正确处理测试信息

先决条件

要启动本教程,您需要如下 ZooOrderApp 项目:

  1. 完成 第 2 章 设置您的环境 指南。
  2. 下面是其中之一:

运行路由

运行路由:

  1. 打开 ZooOrderApp 项目。
  2. Project Explorer 中,选择 ZooOrderApp/Camel Contexts/blueprint.xml

    tutRunCBRrouteCamContext
  3. 右键单击 blueprint.xml,然后选择 Run As Local Camel Context (无需测试)。

    注意

    如果您选择 Local Camel Context,该工具会自动尝试针对提供的 JUnit 测试运行路由上下文。由于 JUnit 测试不存在,因此工具将恢复到在没有测试的情况下运行路由上下文。在 第 9 章 使用 JUnit 测试路由 教程中,您可以创建一个 JUnit 测试案例来测试 ZooOrderApp 项目。

    Console 面板将打开,以显示反映项目执行进度的日志消息。开始时,Maven 下载更新本地 Maven 存储库所需的资源。Maven 下载过程可能需要几分钟时间。

  4. 等待消息(与以下内容类似)在输出末尾出现:这些消息表示路由成功执行:

    ...
    [Blueprint Event Dispatcher: 1] BlueprintCamelContext INFO  Route: _route1 started and consuming from:Endpoint[file://src/data?noop=true]
    [Blueprint Event Dispatcher: 1] BlueprintCamelContext INFO  Total 1 routes, of which 1 are started.
    [Blueprint Event Dispatcher: 1]BlueprintCamelContext INFO  Apache Camel 2.21.0.redhat-3 (CamelContext: ...) started in 0.163 seconds
    [Blueprint Event Dispatcher: 1] BlueprintCamelContext INFO  Apache Camel 2.21.0.redhat-3 (CamelContext: ...) started in 0.918 seconds
  5. 要关闭路由,请点击 Console 视图顶部的 console’s shutdown button

验证路由

要验证路由是否已正确执行,您可以检查消息 XML 文件是否从源文件夹(src/data)复制到目标文件夹(target/messages/received)。

  1. Project Explorer 中,选择 ZooOrderApp
  2. 右键单击,然后选择 Refresh
  3. Project Explorer 中,找到 target/messages/ 文件夹并展开,以验证 target/messages/received 文件夹是否包含六个消息文件 message1.xmlmessage6.xml

    消息目的地
  4. 双击 message1.xml 在路由编辑器的 Design 选项卡中打开它,然后选择 Source 选项卡来查看 XML 代码:

    <?xml version="1.0" encoding="UTF-8"?>
    
    <order>
      <customer>
        <name>Bronx Zoo</name>
        <city>Bronx NY</city>
        <country>USA</country>
      </customer>
      <orderline>
        <animal>wombat</animal>
        <quantity>12</quantity>
      </orderline>
    </order>

后续步骤

第 5 章 添加基于内容的路由器 教程中,您添加一个基于 Content-Based Router,它使用消息的内容来确定其目的地。

Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.