rabbitmq-tutorials/java
Paul Muriel Biya-Bi 4d50239ceb Avoid ArrayIndexOutOfBoundsException in EmitLogDirect
It is true that the EmitLogDirect.getMessage() method only calls the
EmitLogDirect.joinStrings() method when the length of the strings array
argument is at least 2. However, it is safe make our method more robust
by avoiding the ArrayIndexOutOfBoundsException exception as much as we
can. Who knows? Maybe the EmitLogDirect.joinStrings() method could be
extracted in a utility class and used in cases where the startIndex
could potentially be equal to the length of the passed array.
2019-03-30 20:16:03 -04:00
..
EmitLog.java Update Java tutorials to Java 8 2018-12-04 10:55:14 +01:00
EmitLogDirect.java Avoid ArrayIndexOutOfBoundsException in EmitLogDirect 2019-03-30 20:16:03 -04:00
EmitLogHeader.java Update Java tutorials to Java 8 2018-12-04 10:55:14 +01:00
EmitLogTopic.java Update Java tutorials to Java 8 2018-12-04 10:55:14 +01:00
NewTask.java Update Java tutorials to Java 8 2018-12-04 10:55:14 +01:00
README.md Recommend starting consumer first 2019-03-27 19:29:41 +03:00
ReceiveLogHeader.java Update Java tutorials to Java 8 2018-12-04 10:55:14 +01:00
ReceiveLogs.java Update Java tutorials to Java 8 2018-12-04 10:55:14 +01:00
ReceiveLogsDirect.java Update Java tutorials to Java 8 2018-12-04 10:55:14 +01:00
ReceiveLogsTopic.java Update Java tutorials to Java 8 2018-12-04 10:55:14 +01:00
recompile.sh Java client: README updates, closes #217 2019-03-27 19:27:42 +03:00
Recv.java Update Java tutorials to Java 8 2018-12-04 10:55:14 +01:00
RPCClient.java Update Java tutorials to Java 8 2018-12-04 10:55:14 +01:00
RPCServer.java Update Java tutorials to Java 8 2018-12-04 10:55:14 +01:00
Send.java Update Java tutorials to Java 8 2018-12-04 10:55:14 +01:00
Worker.java Update Java tutorials to Java 8 2018-12-04 10:55:14 +01: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.

Requirements

You'll need to download the following JAR files from Maven Central:

For example, with wget:

wget https://repo1.maven.org/maven2/com/rabbitmq/amqp-client/5.6.0/amqp-client-5.6.0.jar
wget https://repo1.maven.org/maven2/org/slf4j/slf4j-api/1.7.25/slf4j-api-1.7.25.jar
wget https://repo1.maven.org/maven2/org/slf4j/slf4j-simple/1.7.25/slf4j-simple-1.7.25.jar

Copy those files in your working directory, along the tutorials Java files.

To compile you only need the Rabbitmq Java client jar on the classpath. To run them you'll need all the dependencies, see examples below.

You can set an environment variable for the jar files on the classpath e.g.

export CP=.:amqp-client-5.6.0.jar:slf4j-api-1.7.25.jar:slf4j-simple-1.7.25.jar
java -cp $CP Send

On Windows, use a semicolon instead of a colon to separate items in the classpath:

set CP=.;amqp-client-5.6.0.jar;slf4j-api-1.7.25.jar;slf4j-simple-1.7.25.jar
java -cp %CP% Send

Code

Tutorial one: "Hello World!":

javac -cp amqp-client-5.6.0.jar Send.java Recv.java

# terminal tab 1
java -cp .:amqp-client-5.6.0.jar:slf4j-api-1.7.25.jar:slf4j-simple-1.7.25.jar Recv

# terminal tab 2
java -cp .:amqp-client-5.6.0.jar:slf4j-api-1.7.25.jar:slf4j-simple-1.7.25.jar Send

Tutorial two: Work Queues:

javac -cp amqp-client-5.6.0.jar NewTask.java Worker.java

# terminal tab 1
java -cp $CP NewTask

# terminal tab 2
java -cp $CP Worker

Tutorial three: Publish/Subscribe

javac -cp amqp-client-5.6.0.jar EmitLog.java ReceiveLogs.java

# terminal tab 1
java -cp $CP ReceiveLogs

# terminal tab 2
java -cp $CP EmitLog