Skip to content

Commit 37531c5

Browse files
committed
Add Java Gradle project
1 parent 85a84e6 commit 37531c5

24 files changed

+528
-0
lines changed

java-gradle/.gitignore

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
.gradle
2+
build/
3+
!gradle/wrapper/gradle-wrapper.jar
4+
!**/src/main/**/build/
5+
!**/src/test/**/build/
6+
7+
### IntelliJ IDEA ###
8+
.idea/
9+
*.iws
10+
*.iml
11+
*.ipr
12+
out/
13+
!**/src/main/**/out/
14+
!**/src/test/**/out/
15+
16+
### Eclipse ###
17+
.apt_generated
18+
.classpath
19+
.factorypath
20+
.project
21+
.settings
22+
.springBeans
23+
.sts4-cache
24+
bin/
25+
!**/src/main/**/bin/
26+
!**/src/test/**/bin/
27+
28+
### NetBeans ###
29+
/nbproject/private/
30+
/nbbuild/
31+
/dist/
32+
/nbdist/
33+
/.nb-gradle/
34+
35+
### VS Code ###
36+
.vscode/
37+
38+
### Mac OS ###
39+
.DS_Store

java-gradle/README.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# Java code for RabbitMQ tutorials
2+
3+
Here you can find the Java code examples from [RabbitMQ
4+
tutorials](https://www.rabbitmq.com/getstarted.html).
5+
6+
To successfully use the examples you will need a RabbitMQ node running locally.
7+
8+
## Requirements
9+
10+
### Linux
11+
12+
- Note the source files are symbolic links to the [java](https://github.com/rabbitmq/rabbitmq-tutorials/tree/main/java) directory.
13+
14+
### Windows
15+
16+
- Run pull-source-files.bat to replace symbolic link to the actual source file.
17+
18+
```shell
19+
.\pull-source-files.bat
20+
```
21+
22+
## Code
23+
24+
#### [Tutorial one: "Hello World!"](https://www.rabbitmq.com/tutorials/tutorial-one-java.html):
25+
26+
```shell
27+
# terminal tab 1
28+
gradle -Pmain=Recv run
29+
30+
# terminal tab 2
31+
gradle -Pmain=Send run
32+
```
33+
34+
#### [Tutorial two: Work Queues](https://www.rabbitmq.com/tutorials/tutorial-two-java.html):
35+
36+
```shell
37+
# terminal tab 1
38+
gradle -Pmain=Worker run
39+
gradle -Pmain=Worker run
40+
41+
# terminal tab 2
42+
gradle -Pmain=NewTask run --args "First Message"
43+
gradle -Pmain=NewTask run --args "Second Message"
44+
gradle -Pmain=NewTask run --args "Third Message"
45+
gradle -Pmain=NewTask run --args "Fourth Message"
46+
gradle -Pmain=NewTask run --args "Fifth Message"
47+
```
48+
49+
#### [Tutorial three: Publish/Subscribe](https://www.rabbitmq.com/tutorials/tutorial-three-java.html)
50+
51+
```shell
52+
# terminal tab 1
53+
gradle -Pmain=ReceiveLogs run
54+
55+
# terminal tab 2
56+
gradle -Pmain=EmitLog run
57+
```
58+
59+
#### [Tutorial four: Routing](https://www.rabbitmq.com/tutorials/tutorial-four-java.html)
60+
61+
```shell
62+
# terminal tab 1
63+
gradle -Pmain=ReceiveLogsDirect run --args "warning error"
64+
65+
# terminal tab 2
66+
gradle -Pmain=ReceiveLogsDirect run --args "info warning error"
67+
68+
# terminal tab 3
69+
gradle -Pmain=EmitLogDirect run --args "error Run. Run. Or it will explode"
70+
```
71+
72+
#### [Tutorial five: Topics](https://www.rabbitmq.com/tutorials/tutorial-five-java.html)
73+
74+
```shell
75+
# To receive all the logs:
76+
gradle -Pmain=ReceiveLogsTopic run --args "#"
77+
78+
# To receive all logs from the facility "kern":
79+
gradle -Pmain=ReceiveLogsTopic run --args "kern.*"
80+
81+
# Or if you want to hear only about "critical" logs:
82+
gradle -Pmain=ReceiveLogsTopic run --args "*.critical"
83+
84+
# You can create multiple bindings:
85+
gradle -Pmain=ReceiveLogsTopic run --args "kern.* *.critical"
86+
87+
# And to emit a log with a routing key "kern.critical" type:
88+
gradle -Pmain=EmitLogTopic run --args "kern.critical A critical kernel error"
89+
```
90+
91+
#### [Tutorial six: RPC](https://www.rabbitmq.com/tutorials/tutorial-six-java.html)
92+
93+
```shell
94+
# Our RPC service is now ready. We can start the server:
95+
gradle -Pmain=RPCServer run
96+
97+
# To request a fibonacci number run the client:
98+
gradle -Pmain=RPCClient run
99+
```
100+
101+
#### [Tutorial seven: Publisher Confirms](https://www.rabbitmq.com/tutorials/tutorial-seven-java.html)
102+
103+
```shell
104+
#
105+
gradle -Pmain=PublisherConfirms run
106+
```

java-gradle/build.gradle

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
plugins {
2+
id 'application'
3+
}
4+
5+
group 'com.rabbitmq.client'
6+
version '1.0-SNAPSHOT'
7+
8+
repositories {
9+
mavenCentral()
10+
}
11+
12+
dependencies {
13+
implementation 'com.rabbitmq:amqp-client:5.16.0'
14+
implementation 'org.slf4j:slf4j-simple:2.0.5'
15+
testImplementation 'org.assertj:assertj-core:3.21.0'
16+
testImplementation 'org.mockito:mockito-core:4.3.1'
17+
testImplementation 'io.dropwizard.metrics:metrics-core:3.1.2'
18+
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
19+
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
20+
}
21+
22+
test {
23+
useJUnitPlatform()
24+
}
25+
26+
application {
27+
mainClassName = project.hasProperty("main") ?
28+
project.getProperty("main") : "NULL"
29+
}
59.3 KB
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)