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 Copy linkLink copied to clipboard!
To build the example, Maven must be configured to use the Red Hat repository.
3.2. Preparing the broker Copy linkLink copied to clipboard!
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 queuecommand 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 --anycastCopy 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 Copy linkLink copied to clipboard!
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.javaCopy to Clipboard Copied! Toggle word wrap Toggle overflow Use a text editor to create a new
<project-dir>/pom.xmlfile. Add the following XML to it:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Change to the project directory and use the
mvncommand to compile the program.mvn clean package
mvn clean packageCopy to Clipboard Copied! Toggle word wrap Toggle overflow Use the
javacommand to run the program.java -jar target/example-1.0.0-SNAPSHOT.jar
java -jar target/example-1.0.0-SNAPSHOT.jarCopy 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 Copy linkLink copied to clipboard!
More example programs are available from the AMQP 1.0 JMS Spring Boot project and the Spring project.