4.3. 生成和使用测试信息

启动代理后,您应该验证其是否在正确运行。这涉及生成一些测试信息,将它们发送到代理,然后使用它们。

流程

  1. 使用 artemis producer 命令生成几个测试消息,并将它们发送到代理。

    此命令会向 helloworld 地址发送 100 条消息,该地址会在代理上自动创建。生产者使用默认端口 61616 连接到代理,该端口接受所有支持的消息传递协议。

    $ /opt/redhat/amq-broker/amq-broker-7.2.0/bin/artemis producer --destination helloworld --message-count 100 --url tcp://localhost:61616
    Producer ActiveMQQueue[helloworld], thread=0 Started to calculate elapsed time ...
    
    Producer ActiveMQQueue[helloworld], thread=0 Produced: 100 messages
    Producer ActiveMQQueue[helloworld], thread=0 Elapsed time in second : 1 s
    Producer ActiveMQQueue[helloworld], thread=0 Elapsed time in milli second : 1289 milli seconds
  2. 使用 Web 控制台查看存储在代理中的消息。

    1. 在 Web 浏览器中,导航到 http://localhost:8161
    2. 使用您在创建代理实例时创建的默认用户名和密码登录控制台。

      此时会显示 Attributes 选项卡。

    3. Attributes 选项卡上,导航到 addresseshelloworld"anycast"helloworld

      在上一步中,您发送了消息到 helloworld 地址。这会使用队列(也称为 helloworld )创建新的任播 helloworld地址。Message count 属性显示发送到 helloworld 的所有 100 个消息目前都存储在此队列中。

      图 4.1. 消息计数

      消息计数
  3. 使用 artemis consumer 命令,使用存储在代理中的 50 个消息。

    这个命令会使用您之前发送到代理的 50 个信息。

    $ /opt/redhat/amq-broker/amq-broker-7.2.0/bin/artemis consumer --destination helloworld --message-count 50 --url tcp://localhost:61616
    
    Consumer:: filter = null
    Consumer ActiveMQQueue[helloworld], thread=0 wait until 50 messages are consumed
    Consumer ActiveMQQueue[helloworld], thread=0 Consumed: 50 messages
    Consumer ActiveMQQueue[helloworld], thread=0 Consumer thread finished
  4. 在 Web 控制台中,验证 Message 计数 现在是否为 50。

    50 个消息被使用,保留 50 个消息存储在 helloworld 队列中。

  5. 停止代理,并验证剩余的 50 个消息仍然存储在 helloworld 队列中。

    1. 在代理运行的终端中,按 Ctrl+C 以停止代理。
    2. 重新启动代理。

      $ /var/opt/amq-broker/mybroker/bin/artemis run
    3. 在 Web 控制台中,导航到 helloworld 队列,再验证队列中仍然存储了 50 个消息。
  6. 使用剩余的 50 条消息。

    $ /opt/redhat/amq-broker/amq-broker-7.2.0/bin/artemis consumer --destination helloworld --message-count 50 --url tcp://localhost:61616
    
    Consumer:: filter = null
    Consumer ActiveMQQueue[helloworld], thread=0 wait until 50 messages are consumed
    Consumer ActiveMQQueue[helloworld], thread=0 Consumed: 50 messages
    Consumer ActiveMQQueue[helloworld], thread=0 Consumer thread finished
  7. 在 Web 控制台中,验证 Message count 是否为 0。

    helloworld 队列中存储的所有消息都被使用,队列现在为空。