5.3. 运行 AMQ Broker 示例程序

AMQ Broker 附带了许多示例程序,演示产品的基本和高级功能。您可以使用 Maven 来运行这些程序。

先决条件

步骤

  1. 进入您要运行的示例目录。

    示例程序位于 <install-dir>/examples 中。例如:

    $ cd <install-dir>/examples/features/standard/queue
  2. 使用 mvn clean verify 命令来运行示例程序。

    Maven 启动代理并运行示例程序。第一次运行示例程序时,Maven 会下载任何缺少的依赖项,这可能需要一些时间才能运行。

    在本例中,运行队列 示例程序创建一个制作者,发送测试消息,然后创建一个接收消息的消费者:

    $ mvn clean verify
    [INFO] Scanning for projects...
    [INFO]
    [INFO] -------------< org.apache.activemq.examples.broker:queue >--------------
    [INFO] Building ActiveMQ Artemis JMS Queue Example 2.6.1.amq-720004-redhat-1
    [INFO] --------------------------------[ jar ]---------------------------------
    ...
    server-out:2018-12-05 16:37:57,023 INFO  [org.apache.activemq.artemis.core.server] AMQ221001: Apache ActiveMQ Artemis Message Broker version 2.6.1.amq-720004-redhat-1 [0.0.0.0, nodeID=06f529d3-f8d6-11e8-9bea-0800271b03bd]
    [INFO] Server started
    [INFO]
    [INFO] --- artemis-maven-plugin:2.6.1.amq-720004-redhat-1:runClient (runClient) @ queue ---
    Sent message: This is a text message
    Received message: This is a text message
    [INFO]
    [INFO] --- artemis-maven-plugin:2.6.1.amq-720004-redhat-1:cli (stop) @ queue ---
    server-out:2018-12-05 16:37:59,519 INFO  [org.apache.activemq.artemis.core.server] AMQ221002: Apache ActiveMQ Artemis Message Broker version 2.6.1.amq-720004-redhat-1 [06f529d3-f8d6-11e8-9bea-0800271b03bd] stopped, uptime 3.734 seconds
    server-out:Server stopped!
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time:  48.681 s
    [INFO] Finished at: 2018-12-05T16:37:59-05:00
    [INFO] ------------------------------------------------------------------------
    注意

    些示例程序使用 UDP 集群,默认情况下可能无法在您的环境中工作。要成功运行这些示例,请将定向到 224.0.0.0 的流量重定向到回环接口:

    $ sudo route add -net 224.0.0.0 netmask 240.0.0.0 dev lo