rabbitmq-tutorials/java-mvn
dependabot[bot] 9d63e34c7f
chore(deps-dev): bump org.junit.jupiter:junit-jupiter in /java-mvn
Bumps [org.junit.jupiter:junit-jupiter](https://github.com/junit-team/junit5) from 5.11.4 to 5.12.0.
- [Release notes](https://github.com/junit-team/junit5/releases)
- [Commits](https://github.com/junit-team/junit5/compare/r5.11.4...r5.12.0)

---
updated-dependencies:
- dependency-name: org.junit.jupiter:junit-jupiter
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-02-21 17:08:42 +00:00
..
.mvn/wrapper Bump Maven 2024-04-22 16:04:40 +02:00
src Add Java files for publisher confirms tutorial 2019-08-26 14:30:59 +02:00
mvnw Bump Maven 2024-04-22 16:04:40 +02:00
mvnw.cmd Bump Maven 2024-04-22 16:04:40 +02:00
pom.xml chore(deps-dev): bump org.junit.jupiter:junit-jupiter in /java-mvn 2025-02-21 17:08:42 +00:00
pull-source-files.bat Create README.md for java-mvn 2024-05-20 22:56:17 +09:00
README.md Create README.md for java-mvn 2024-05-20 22:56:17 +09:00

Java code for RabbitMQ tutorials

Here you can find the Java code examples from RabbitMQ tutorials.

To successfully use the examples you will need a RabbitMQ node running locally.

You can easily set this up by installing RabbitMQ.

Requirements

Linux

  • Note the source files are symbolic links to the java directory.

Windows

  • Run pull-source-files.bat to replace symbolic link to the actual source file.
./pull-source-files.bat

Code

Tutorial one: "Hello World!":

# terminal tab 1
./mvnw compile exec:java -D"exec.mainClass=Recv"

# terminal tab 2
./mvnw compile exec:java -D"exec.mainClass=Send"

Tutorial two: Work Queues:

# terminal tab 1
./mvnw compile exec:java -D"exec.mainClass=Worker"

# terminal tab 2
./mvnw compile exec:java -D"exec.mainClass=Worker"

# terminal tab 3
./mvnw compile exec:java -D"exec.mainClass=NewTask" -D"exec.args='First Message'"
./mvnw compile exec:java -D"exec.mainClass=NewTask" -D"exec.args='Second Message'"
./mvnw compile exec:java -D"exec.mainClass=NewTask" -D"exec.args='Third Message'"
./mvnw compile exec:java -D"exec.mainClass=NewTask" -D"exec.args='Fourth Message'"
./mvnw compile exec:java -D"exec.mainClass=NewTask" -D"exec.args='Fifth Message'"

Tutorial three: Publish/Subscribe

# terminal tab 1
./mvnw compile exec:java -D"exec.mainClass=ReceiveLogs"

# terminal tab 2
./mvnw compile exec:java -D"exec.mainClass=ReceiveLogs"

# terminal tab 3
./mvnw compile exec:java -D"exec.mainClass=EmitLog"

Tutorial four: Routing

# terminal tab 1
./mvnw compile exec:java -D"exec.mainClass=ReceiveLogsDirect" -D"exec.args=warning error"

# terminal tab 2
./mvnw compile exec:java -D"exec.mainClass=ReceiveLogsDirect" -D"exec.args=info warning error"

# terminal tab 3
./mvnw compile exec:java -D"exec.mainClass=EmitLogDirect" -D"exec.args=info 'Run. Run. Or it will explode'"
./mvnw compile exec:java -D"exec.mainClass=EmitLogDirect" -D"exec.args=warning 'Run. Run. Or it will explode'"
./mvnw compile exec:java -D"exec.mainClass=EmitLogDirect" -D"exec.args=error 'Run. Run. Or it will explode'"

Tutorial five: Topics

# terminal tab 1
# To receive all the logs:
./mvnw compile exec:java -D"exec.mainClass=ReceiveLogsTopic" -D"exec.args=#"

# To receive all logs from the facility "kern":
./mvnw compile exec:java -D"exec.mainClass=ReceiveLogsTopic" -D"exec.args=kern.*"

# Or if you want to hear only about "critical" logs:
./mvnw compile exec:java -D"exec.mainClass=ReceiveLogsTopic" -D"exec.args=*.critical"

# You can create multiple bindings:
./mvnw compile exec:java -D"exec.mainClass=ReceiveLogsTopic" -D"exec.args=kern.* *.critical"

# terminal tab 2
# And to emit a log with a routing key "kern.critical" type:
./mvnw compile exec:java -D"exec.mainClass=EmitLogTopic" -D"exec.args=kern.critical A critical kernel error"

Tutorial six: RPC

# terminal tab 1
# Our RPC service is now ready. We can start the server:
./mvnw compile exec:java -D"exec.mainClass=RPCServer"

# terminal tab 2
# To request a fibonacci number run the client:
./mvnw compile exec:java -D"exec.mainClass=RPCClient"

Tutorial seven: Publisher Confirms

# terminal tab 1
./mvnw compile exec:java -D"exec.mainClass=PublisherConfirms"