In this workshop we will learn the basic concepts of a Message Queue, and we will learn how to write a small Golang application to interact with RabbitMQ as our message broker.
- You have installed Docker (https://docs.docker.com/get-docker/)
- You have copied
.env.exampleto.envand have entered the variables we will provide during the workshop
Please use powershell (and not cmd) and change the volume mount as shown below
--volume="${pwd}:/app"instead of:
--volume="$PWD:/app"Lets get a message from a queue!
This application will try to get a single message from a queue called "results".
docker run --rm -it --volume="$PWD:/app" -w /app golang:1-alpine go run cmd/step1/main.goWe can do better than polling for every single message. Let's consume from a queue instead.
docker run --rm -it --volume="$PWD:/app" -w /app golang:1-alpine go run cmd/step2/main.goNo more shared queue, we want to receive all messages.
This program will create an exclusive queue and bind it to the exchange called "results" with routing key "#".
The routing key determines what messages your queue will receive, a # means all messages.
docker run --rm -it --volume="$PWD:/app" -w /app golang:1-alpine go run cmd/step3/main.goUp until now we have been receiving all messages. In this example we will use the routing key to tell RabbitMQ we only want to receive LAeq messages.
docker run --rm -it --volume="$PWD:/app" -w /app golang:1-alpine go run cmd/step4/main.goBut what it you want to send data to the queue? That goes through an exchange! We will publish something to the results exchange and then use the code from step 4 to receive this message! Note that if you don't use a routing key (like step 2) you will receive these messages mixed with our prepared messages.
docker run --rm -it --volume="$PWD:/app" -w /app golang:1-alpine go run cmd/step5/main.go