Skip to content

Commit d970483

Browse files
committed
Create README.md for java-mvn
1 parent 20c77ff commit d970483

File tree

2 files changed

+120
-0
lines changed

2 files changed

+120
-0
lines changed

java-mvn/README.md

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

java-mvn/pull-source-files.bat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
copy ..\java\*.java src\main\java\

0 commit comments

Comments
 (0)