이 콘텐츠는 선택한 언어로 제공되지 않습니다.
Chapter 5. Examples
This chapter demonstrates the use of AMQ JMS Pool through example programs.
For more examples, see the Pooled JMS examples.
5.1. Prerequisites 링크 복사링크가 클립보드에 복사되었습니다!
- To build the examples, Maven must be configured to use the Red Hat repository or a local repository.
- To run the examples, your system must have a running and configured broker.
5.2. Establishing a connection 링크 복사링크가 클립보드에 복사되었습니다!
This example creates a new connection pool, binds it to a connection factory, and uses the pool to create a new connection.
Example: Establishing a connection - Connect.java
5.3. Configuring the pool 링크 복사링크가 클립보드에 복사되었습니다!
This example demonstrates setting connection and session configuration options.
Example: Configuring the pool - ConnectWithConfiguration.java
5.4. Running the examples 링크 복사링크가 클립보드에 복사되었습니다!
To compile and run the example programs, 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 Java listings to the following locations:
<project-dir>/src/main/java/net/example/Connect.java <project-dir>/src/main/java/net/example/ConnectWithConfiguration.java
<project-dir>/src/main/java/net/example/Connect.java <project-dir>/src/main/java/net/example/ConnectWithConfiguration.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 Replace
${qpid-jms-version}with your preferred Qpid JMS version.Change to the project directory and use the
mvncommand to compile the program.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 program.On Linux or UNIX:
java -cp "target/classes:target/dependency/*" net.example.Connect amqp://localhost
java -cp "target/classes:target/dependency/*" net.example.Connect amqp://localhostCopy to Clipboard Copied! Toggle word wrap Toggle overflow On Windows:
java -cp "target\classes;target\dependency\*" net.example.Connect amqp://localhost
java -cp "target\classes;target\dependency\*" net.example.Connect amqp://localhostCopy to Clipboard Copied! Toggle word wrap Toggle overflow
These sample commands run the Connect example. To run another example, replace Connect with the class name of your desired example.
Running the Connect example on Linux results in the following output:
java -cp "target/classes:target/dependency/*" net.example.Connect amqp://localhost
$ java -cp "target/classes:target/dependency/*" net.example.Connect amqp://localhost
CONNECT: Connected to 'amqp://localhost'