Chapter 3. Getting started
This chapter guides you through the steps to set up your environment and run a simple messaging program.
3.1. Prerequisites Copy linkLink copied to clipboard!
- To build the example, Maven must be configured to use the Red Hat repository or a local repository.
-
You must have a message broker listening for connections on
localhost. It must have anonymous access enabled. For more information, see Starting the broker. -
You must have a queue named
example. For more information, see Creating a queue.
3.2. Running Hello World Copy linkLink copied to clipboard!
The Hello World example creates a connection to the broker, sends a message containing a greeting to the example queue, and receives it back. On success, it prints the received message to the console.
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.3. 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.