4.3. テストメッセージの生成および使用
ブローカーの起動後に、ブローカーが適切に実行されていることを確認する必要があります。そのためには、いくつかのテストメッセージを作成してブローカーに送信し、使用します。
手順
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 secondsWeb コンソールを使用して、ブローカーに保存されているメッセージを表示します。
- Web ブラウザーで、http://localhost:8161 にアクセスします。
ブローカーインスタンスの作成時に作成したデフォルトのユーザー名およびパスワードを使用して、コンソールにログインします。
Attributesタブが表示されます。Attributesタブで menu:addresses[helloworld > queues >"anycast" > helloworld] に移動します。前の手順で、
helloworldアドレスにメッセージを送信しています。これにより、キュー (helloworldという名前) を持つ新しい anycasthelloworldアドレスが作成されました。Message count属性は、現在helloworldに送信された 100 個のメッセージがすべてこのキューに保存されていることを示しています。図4.1 メッセージ数
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 finishedWeb コンソールで、
Message countが 50 であることを確認します。メッセージが 50 個消費され、
helloworldキューに格納されているメッセージ数の残りは 50 個になります。ブローカーを停止し、残りのメッセージ 50 個が
helloworldキューに保存されていることを確認します。- ブローカーが実行されているターミナルで、kbd:[Ctrl+C] を押してブローカーを停止します。
ブローカーを再起動します。
$ /var/opt/amq-broker/mybroker/bin/artemis run-
Web コンソールで、
helloworldキューに戻り、キューに保存されているメッセージが 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 finishedWeb コンソールで、
Message countが 0 であることを確認します。helloworldキューに保存されているメッセージはすべて消費され、キューが空になりました。