第 5 章 运行 AMQ Broker 示例

AMQ Broker 随附许多示例程序,它们演示了该产品的基本和高级功能。您可以运行这些示例来熟悉 AMQ Broker 的功能。

要运行 AMQ Broker 示例,您必须首先通过安装和配置 Apache Maven 和 AMQ Maven 存储库来设置机器。然后,您可以使用 Maven 运行 AMQ Broker 示例程序。

5.1. 将机器设置为运行 AMQ Broker 示例

在运行附带的 AMQ Broker 示例程序前,您必须先下载并安装 Maven 和 AMQ Maven 存储库,并配置 Maven 设置文件。

5.1.1. 下载并安装 Maven

需要 Maven 运行 AMQ Broker 示例。

流程

  1. 进入 Apache Maven 下载页面,再下载您的操作系统的最新发行版。
  2. 为您的操作系统安装 Maven。

    如需更多信息,请参阅 安装 Apache Maven

其他资源

5.1.2. 下载并安装 AMQ Maven 存储库

在您的机器上安装 Maven 后,您将下载并安装 AMQ Maven 存储库。红帽客户门户网站中提供这个软件仓库。

  1. 在 Web 浏览器中,导航到 https://access.redhat.com/downloads/ 并登录。

    此时会显示产品下载页。

  2. Integration and Automation 部分中,点 Red Hat AMQ Broker 链接。

    此时会显示 Software Downloads 页面。

  3. Version 下拉菜单中选择所需的 AMQ Broker 版本。
  4. Releases 选项卡上,点 AMQ Broker Maven Repository 的 Download 链接。

    AMQ Maven 存储库文件作为 zip 文件下载。

  5. 在您的计算机上,将 AMQ 存储库文件解压缩到您选择的目录中。

    在您的计算机上创建新的目录,其中包含名为 maven-repository/ 的子目录中的 Maven 存储库。

5.1.3. 配置 Maven 设置文件

下载并安装 AMQ Maven 存储库后,您必须将存储库添加到 Maven 设置文件中。

流程

  1. 打开 Maven settings.xml 文件。

    settings.xml 文件通常位于 ${user.home}/.m2/ 目录中。

    • 对于 Linux,这是 ~/.m2/
    • 对于 Windows,这是 \Documents and Settings\.m2\\Users\.m2\

    如果您未在 ${user.home}/.m2/ 中找到settings.xml 文件,则 Maven 安装的 conf/ 目录中有一个默认版本。将默认 settings.xml 文件复制到 ${user.home}/.m2/ 目录中。

  2. <profiles> 元素中,为 AMQ Maven 存储库添加配置集。

    <!-- Configure the JBoss AMQ Maven repository -->
    <profile>
      <id>jboss-amq-maven-repository</id>
      <repositories>
        <repository>
          <id>jboss-amq-maven-repository</id>
          <url>file://<JBoss-AMQ-repository-path></url>  1
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <id>jboss-amq-maven-repository</id>
          <url>file://<JBoss-AMQ-repository-path></url>  2
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
    1 2
    <JBoss-AMQ-repository-path> 替换为您安装的 Maven 存储库的位置。通常,此位置以 /maven-repository 结尾。例如:
    <url>file:///path/to/repo/amq-broker-7.2.0-maven-repository/maven-repository</url>
  3. <activeProfiles> 元素中,将 AMQ Maven 存储库设置为活跃:

    <activeProfiles>
      <activeProfile>jboss-amq-maven-repository</activeProfile>
    ...
    </activeProfiles>
  4. 如果您从 Maven 安装中复制了默认的 settings.xml,取消注释 <active-profiles> 部分(如果默认被注释掉)。
  5. 保存并关闭 settings.xml
  6. 删除缓存的 ${user.home}/.m2/repository/ 目录。

    如果您的 Maven 存储库包含过时的工件,则构建或部署项目时可能会遇到以下 Maven 错误消息之一:

    • 缺少工件 <artifact-name>
    • [ERROR] Failed to execute goal on project <project-name>; Could not resolve dependencies for <project-name>