A minimal example of publishing and consuming messages with the RabbitMQ Java client, against CloudAMQP or any AMQP 0-9-1 broker such as LavinMQ or RabbitMQ.
Publisher.javapublishes a persistent message with publisher confirms.Worker.javaconsumes with manual acknowledgements and a prefetch of 10.Amqp.javaconnects using theBROKER_URLenvironment variable.
Tool versions are in mise.toml; install them with mise,
or use Java 21+ and Maven 3.
export BROKER_URL="amqps://user:password@host/vhost"
mvn compile exec:java -Dexec.mainClass=Worker # in one terminal
mvn compile exec:java -Dexec.mainClass=Publisher # in anotherWithout BROKER_URL it connects to amqp://guest:guest@localhost.
mvn test publishes and consumes a message through a real broker on
localhost. CI runs it against LavinMQ.