このコンテンツは選択した言語では利用できません。

Chapter 3. Getting started


This chapter guides you through a simple exercise to help you get started using AMQ Core Protocol JMS.

3.1. Prerequisites

3.2. Preparing the broker

The example programs require a running broker with a queue named exampleQueue. Follow these steps to define the queue and start the broker:

Procedure

  1. Install the broker.
  2. Create a broker instance. Enable anonymous access.
  3. Start the broker instance and check the console for any critical errors logged during startup.

    $ <broker-instance-dir>/bin/artemis run
    ...
    14:43:20,158 INFO  [org.apache.activemq.artemis.integration.bootstrap] AMQ101000: Starting ActiveMQ Artemis Server
    ...
    15:01:39,686 INFO  [org.apache.activemq.artemis.core.server] AMQ221020: Started Acceptor at 0.0.0.0:5672 for protocols [AMQP]
    ...
    15:01:39,691 INFO  [org.apache.activemq.artemis.core.server] AMQ221007: Server is now live
    Copy to Clipboard Toggle word wrap
  4. Use the artemis queue command to create a queue called exampleQueue.

    <broker-instance-dir>/bin/artemis queue create --name exampleQueue --auto-create-address --anycast
    Copy to Clipboard Toggle word wrap

    You are prompted to answer a series of questions. For yes or no questions, type N. Otherwise, press Enter to accept the default value.

3.3. Running your first example

Procedure

  1. Use Maven to build the examples by running the following command in the <install-dir>/examples/features/standard/queue directory.

    mvn clean package dependency:copy-dependencies -DincludeScope=runtime -DskipTests
    Copy to Clipboard Toggle word wrap

    The addition of dependency:copy-dependencies results in the dependencies being copied into the target/dependency directory.

  2. Use the java command to run the example.

    On Linux or UNIX:

    java -cp "target/classes:target/dependency/*" org.apache.activemq.artemis.jms.example.QueueExample
    Copy to Clipboard Toggle word wrap

    On Windows:

    java -cp "target\classes;target\dependency\*" org.apache.activemq.artemis.jms.example.QueueExample
    Copy to Clipboard Toggle word wrap

The example creates a consumer and producer for a queue named exampleQueue. It sends a text message and then receives it back, printing the received message to the console.

Running it on Linux results in the following output.

$ 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
Copy to Clipboard Toggle word wrap

The source code for the example is in the <install-dir>/examples/features/standard/queue/src directory. Additional examples are available in the <install-dir>/examples/features/standard directory.

トップに戻る
Red Hat logoGithubredditYoutubeTwitter

詳細情報

試用、購入および販売

コミュニティー

Red Hat ドキュメントについて

Red Hat をお使いのお客様が、信頼できるコンテンツが含まれている製品やサービスを活用することで、イノベーションを行い、目標を達成できるようにします。 最新の更新を見る.

多様性を受け入れるオープンソースの強化

Red Hat では、コード、ドキュメント、Web プロパティーにおける配慮に欠ける用語の置き換えに取り組んでいます。このような変更は、段階的に実施される予定です。詳細情報: Red Hat ブログ.

会社概要

Red Hat は、企業がコアとなるデータセンターからネットワークエッジに至るまで、各種プラットフォームや環境全体で作業を簡素化できるように、強化されたソリューションを提供しています。

Theme

© 2025 Red Hat