Skip to content

Commit d8dddec

Browse files
committed
Add Java AMQP 1.0 tutorial
1 parent 646ddb5 commit d8dddec

22 files changed

Lines changed: 1828 additions & 0 deletions

.github/dependabot.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@ updates:
1313
versions: [ "[6.0,)" ]
1414
- dependency-name: "org.junit.platform:*"
1515
versions: [ "[6.0,)" ]
16+
- package-ecosystem: "maven"
17+
directory: "/java-amqp"
18+
schedule:
19+
interval: "daily"
20+
open-pull-requests-limit: 20
21+
target-branch: "main"
22+
ignore:
23+
- dependency-name: "org.junit.jupiter:*"
24+
versions: [ "[6.0,)" ]
25+
- dependency-name: "org.junit.platform:*"
26+
versions: [ "[6.0,)" ]
1627
- package-ecosystem: "maven"
1728
directory: "/java-stream-mvn"
1829
schedule:
61.1 KB
Binary file not shown.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.6/apache-maven-3.9.6-bin.zip
18+
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar

java-amqp/README.md

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# Java code for RabbitMQ tutorials (AMQP 1.0 client)
2+
3+
Here you can find Java examples for the [RabbitMQ tutorials](https://www.rabbitmq.com/getstarted.html) using the [RabbitMQ AMQP 1.0 Java client](https://rabbitmq.github.io/rabbitmq-amqp-java-client/stable/htmlsingle/).
4+
5+
You need a RabbitMQ node running locally. The client requires **RabbitMQ 4.0 or newer** with AMQP 1.0 (enabled by default on port **5672**). The examples use the default `guest` user. See also the [AMQP 1.0 client libraries overview](https://www.rabbitmq.com/client-libraries/amqp-client-libraries).
6+
7+
This directory is a self-contained [Maven](https://maven.apache.org/) project. Use `./mvnw` on Unix-like systems or `mvnw.cmd` on Windows.
8+
9+
Run integration tests with `./mvnw test` (they expect a broker on `localhost`).
10+
11+
## Code
12+
13+
#### Tutorial one: "Hello World!"
14+
15+
```shell
16+
# terminal tab 1
17+
./mvnw compile exec:java -Dexec.mainClass=Recv
18+
19+
# terminal tab 2
20+
./mvnw compile exec:java -Dexec.mainClass=Send
21+
```
22+
23+
#### Tutorial two: Work Queues
24+
25+
```shell
26+
# terminal tab 1
27+
./mvnw compile exec:java -Dexec.mainClass=Worker
28+
29+
# terminal tab 2
30+
./mvnw compile exec:java -Dexec.mainClass=Worker
31+
32+
# terminal tab 3
33+
./mvnw compile exec:java -Dexec.mainClass=NewTask -Dexec.args="First Message"
34+
./mvnw compile exec:java -Dexec.mainClass=NewTask -Dexec.args="Second Message"
35+
./mvnw compile exec:java -Dexec.mainClass=NewTask -Dexec.args="Third Message"
36+
./mvnw compile exec:java -Dexec.mainClass=NewTask -Dexec.args="Fourth Message"
37+
./mvnw compile exec:java -Dexec.mainClass=NewTask -Dexec.args="Fifth Message"
38+
```
39+
40+
#### Tutorial three: Publish/Subscribe
41+
42+
```shell
43+
# terminal tab 1
44+
./mvnw compile exec:java -Dexec.mainClass=ReceiveLogs
45+
46+
# terminal tab 2
47+
./mvnw compile exec:java -Dexec.mainClass=ReceiveLogs
48+
49+
# terminal tab 3
50+
./mvnw compile exec:java -Dexec.mainClass=EmitLog
51+
```
52+
53+
#### Tutorial four: Routing
54+
55+
```shell
56+
# terminal tab 1
57+
./mvnw compile exec:java -Dexec.mainClass=ReceiveLogsDirect -Dexec.args="warning error"
58+
59+
# terminal tab 2
60+
./mvnw compile exec:java -Dexec.mainClass=ReceiveLogsDirect -Dexec.args="info warning error"
61+
62+
# terminal tab 3
63+
./mvnw compile exec:java -Dexec.mainClass=EmitLogDirect -Dexec.args="info Run. Run. Or it will explode."
64+
./mvnw compile exec:java -Dexec.mainClass=EmitLogDirect -Dexec.args="warning Run. Run. Or it will explode."
65+
./mvnw compile exec:java -Dexec.mainClass=EmitLogDirect -Dexec.args="error Run. Run. Or it will explode."
66+
```
67+
68+
#### Tutorial five: Topics
69+
70+
```shell
71+
# terminal tab 1
72+
# To receive all the logs:
73+
./mvnw compile exec:java -Dexec.mainClass=ReceiveLogsTopic -Dexec.args="#"
74+
75+
# To receive all logs from the facility "kern":
76+
./mvnw compile exec:java -Dexec.mainClass=ReceiveLogsTopic -Dexec.args="kern.*"
77+
78+
# Or if you want to hear only about "critical" logs:
79+
./mvnw compile exec:java -Dexec.mainClass=ReceiveLogsTopic -Dexec.args="*.critical"
80+
81+
# You can create multiple bindings:
82+
./mvnw compile exec:java -Dexec.mainClass=ReceiveLogsTopic -Dexec.args="kern.* *.critical"
83+
84+
# terminal tab 2
85+
# And to emit a log with a routing key "kern.critical" type:
86+
./mvnw compile exec:java -Dexec.mainClass=EmitLogTopic -Dexec.args="kern.critical A critical kernel error"
87+
```
88+
89+
#### Tutorial six: RPC
90+
91+
```shell
92+
# terminal tab 1
93+
./mvnw compile exec:java -Dexec.mainClass=RPCServer
94+
95+
# terminal tab 2
96+
./mvnw compile exec:java -Dexec.mainClass=RPCClient
97+
```
98+
99+
#### Tutorial seven: Publisher Confirms
100+
101+
```shell
102+
./mvnw compile exec:java -Dexec.mainClass=PublisherConfirms
103+
```

0 commit comments

Comments
 (0)