此内容没有您所选择的语言版本。
Chapter 3. Getting started
This chapter guides you through a simple exercise to help you get started using AMQ Spring Boot Starter.
3.1. Prerequisites 复制链接链接已复制到粘贴板!
To build the example, Maven must be configured to use the Red Hat repository.
3.2. Preparing the broker 复制链接链接已复制到粘贴板!
The example programs require a running broker with a queue named example
. Follow these steps to define the queue and start the broker:
Procedure
- Install the broker.
- Create a broker instance. Enable anonymous access.
Start the broker instance and check the console for any critical errors logged during startup.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Use the
artemis queue
command to create a queue calledexample
.<broker-instance-dir>/bin/artemis queue create --name example --auto-create-address --anycast
<broker-instance-dir>/bin/artemis queue create --name example --auto-create-address --anycast
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 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. Hello World 复制链接链接已复制到粘贴板!
This example sends a greeting to a queue called example
and then receives it back.
Example: Sending and receiving "Hello World!" - HelloWorld.java
Running the example
To compile and run the example program, use the following procedure:
Procedure
-
Create a new project directory. This is referred to as
<project-dir>
in the steps that follow. Copy the example listing to the following location:
<project-dir>/src/main/java/net/example/HelloWorld.java
<project-dir>/src/main/java/net/example/HelloWorld.java
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Use a text editor to create a new
<project-dir>/pom.xml
file. Add the following XML to it:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Change to the project directory and use the
mvn
command to compile the program.mvn clean package
mvn clean package
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Use the
java
command to run the program.java -jar target/example-1.0.0-SNAPSHOT.jar
java -jar target/example-1.0.0-SNAPSHOT.jar
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Running the Hello World example results in the following console output:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
3.4. Additional examples 复制链接链接已复制到粘贴板!
More example programs are available from the AMQP 1.0 JMS Spring Boot project and the Spring project.