3.2. 运行第一个示例

这个示例为名为 exampleQueue 的队列创建使用者和制作者。它发送文本消息,然后接收回消息,将收到的消息打印到控制台。

流程

  1. 通过在 <install-dir>/examples/protocols/openwire/queue 目录中运行以下命令来使用 Maven 构建示例。

    $ mvn clean package dependency:copy-dependencies -DincludeScope=runtime -DskipTests

    添加 dependency:copy-dependencies 会导致依赖项复制到 target/dependency 目录中。

  2. 使用 java 命令来运行示例。

    在 Linux 或 UNIX 中:

    $ java -cp "target/classes:target/dependency/*" org.apache.activemq.artemis.jms.example.QueueExample

    在 Windows 中:

    > java -cp "target\classes;target\dependency\*" org.apache.activemq.artemis.jms.example.QueueExample

在 Linux 上运行它会产生以下输出:

$ java -cp "target/classes:target/dependency/*" org.apache.activemq.artemis.jms.example.QueueExample
Sent message: This is a text message
Received message: This is a text message

这个示例的源代码位于 <install-dir>/examples/protocols/openwire/queue/src 目录中。<install-dir>/examples/protocols/openwire 目录中提供了其他示例。