Dieser Inhalt ist in der von Ihnen ausgewählten Sprache nicht verfügbar.
Chapter 3. Getting started
This chapter guides you through a simple exercise to help you get started using AMQ JMS Pool.
3.1. Prerequisites Link kopierenLink in die Zwischenablage kopiert!
- The Hello World example program is located in the AMQ JMS Pool 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 Link kopierenLink in die Zwischenablage kopiert!
The example programs require a running broker with a queue named queue. 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 calledqueue.<broker-instance-dir>/bin/artemis queue create --name queue --auto-create-address --anycast
<broker-instance-dir>/bin/artemis queue create --name queue --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 Hello World Link kopierenLink in die Zwischenablage kopiert!
Procedure
Use Maven to build the examples by running the following command in the
<install-dir>/examplesdirectory.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.messaginghub.jms.example.HelloWorld
java -cp "target/classes:target/dependency/*" org.messaginghub.jms.example.HelloWorldCopy to Clipboard Copied! Toggle word wrap Toggle overflow On Windows:
java -cp "target\classes;target\dependency\*" org.messaginghub.jms.example.HelloWorld
java -cp "target\classes;target\dependency\*" org.messaginghub.jms.example.HelloWorldCopy to Clipboard Copied! Toggle word wrap Toggle overflow
The example calls createConnection() for each character of the string "Hello World", transferring one at a time. Because AMQ JMS Pool is in use, each call reuses the same underlying JMS Connection object.
Running it on Linux results in the following output.
java -cp "target/classes/:target/dependency/*" org.messaginghub.jms.example.HelloWorld
$ java -cp "target/classes/:target/dependency/*" org.messaginghub.jms.example.HelloWorld
2018-05-17 11:04:23,393 [main ] - INFO JmsPoolConnectionFactory - Provided ConnectionFactory is JMS 2.0+ capable.
2018-05-17 11:04:23,715 [localhost:5672]] - INFO SaslMechanismFinder - Best match for SASL auth was: SASL-ANONYMOUS
2018-05-17 11:04:23,739 [localhost:5672]] - INFO JmsConnection - Connection ID:104dfd29-d18d-4bf5-aab9-a53660f58633:1 connected to remote Broker: amqp://localhost:5672
Hello World
The source code for the example is in the <install-dir>/examples/src/main/java directory. The JNDI and logging configuration is in the <install-dir>/examples/src/main/resources directory.