이 콘텐츠는 선택한 언어로 제공되지 않습니다.

Chapter 3. Getting Started


This chapter guides you through a simple exercise to help you get started using AMQ JMS. Before starting, make sure you have completed the steps in the Chapter 2, Installation chapter for your environment.

To build the examples, you must first configure Maven to discover the client repository.

3.1. Preparing the Broker

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

  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
  4. Use the artemis queue command to create a queue called queue.

    $ BROKER_INSTANCE_DIR/bin/artemis queue create --name queue --auto-create-address --anycast

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

3.2. Running Hello World

Use Maven to build the examples by running the following command in the INSTALL_DIR/examples directory.

Note

In this example, the addition of dependency:copy-dependencies results in the dependencies being copied into the target/dependency directory.

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

Run the HelloWorld example by using one of the following commands.

Linux:   java -cp "target/classes/:target/dependency/*" org.apache.qpid.jms.example.HelloWorld
Windows: java -cp "target\classes\;target\dependency\*" org.apache.qpid.jms.example.HelloWorld

The HelloWorld example creates a connection to the broker, creates a MessageConsumer and MessageProducer for the queue called queue, sends a Hello world! TextMessage, receives it, and prints its contents to the terminal.

For example, running it on Linux results in the following output.

$ java -cp "target/classes/:target/dependency/*" org.apache.qpid.jms.example.HelloWorld
Hello world!

The source code for the example can be found in the INSTALL_DIR/src/main/java directory, with the JNDI and logging configuration found in the INSTALL_DIR/src/main/resources directory.

Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 문서 정보

Legal Notice

Theme

© 2026 Red Hat
맨 위로 이동