|
| 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 | +``` |
0 commit comments