此内容没有您所选择的语言版本。
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 复制链接链接已复制到粘贴板!
- The example programs are located in the AMQ Broker zip file. To get started, you must install the zip file.
- To build the example, Maven must be configured to use the Red Hat repository or a local repository.
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
- 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 calledexampleQueue.<broker-instance-dir>/bin/artemis queue create --name exampleQueue --auto-create-address --anycast
<broker-instance-dir>/bin/artemis queue create --name exampleQueue --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. Running your first example 复制链接链接已复制到粘贴板!
Procedure
Use Maven to build the examples by running the following command in the
<install-dir>/examples/features/standard/queuedirectory.mvn clean package dependency:copy-dependencies -DincludeScope=runtime -DskipTests
mvn clean package dependency:copy-dependencies -DincludeScope=runtime -DskipTestsCopy to Clipboard Copied! Toggle word wrap Toggle overflow The addition of
dependency:copy-dependenciesresults in the dependencies being copied into thetarget/dependencydirectory.Use the
javacommand to run the example.On Linux or UNIX:
java -cp "target/classes:target/dependency/*" org.apache.activemq.artemis.jms.example.QueueExample
java -cp "target/classes:target/dependency/*" org.apache.activemq.artemis.jms.example.QueueExampleCopy to Clipboard Copied! Toggle word wrap Toggle overflow On Windows:
java -cp "target\classes;target\dependency\*" org.apache.activemq.artemis.jms.example.QueueExample
java -cp "target\classes;target\dependency\*" org.apache.activemq.artemis.jms.example.QueueExampleCopy to Clipboard Copied! Toggle word wrap Toggle overflow
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
$ 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
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.