Welcome!
Today we will be showing what a Message Queue is and why it's awesome. We will be doing that in conjunction with the programming language Golang, because it's builtin concurrency makes it a breeze to work with a Message Queue. First of all lets make sure everybody is set up.
You can either use docker or follow the commands below to install golang locally:
- Install Golang or Docker
- Golang: (go.dev/doc/install)
- Verify you can run
go version
and that you have v1.21 or newer
- Verify you can run
- Docker: (https://docs.docker.com/engine/install/)
- Do
docker pull golang:1
- Verify you can run
docker run golang:1 go version
and that you have v1.21 or newer
- Do
- Install an IDE, we recommend GoLand from JetBrains (jetbrains.com/go)
- Should be free to use for students.
- You are now good to GO :)
Download this repository to your laptop.
git clone https://github.com/munisense/message-queue-workshop.git
We will be using go run
here, this compiles and runs your code in a single command.
go run cmd/01_hello_world/main.go
Or via docker compose:
docker compose run --rm golang go run /opt/project/cmd/01_hello_world/main.go
Copy the file .env.default
to a new file called .env
, and fill in the credentials (see the presentation).
go run cmd/02_get_from_a_queue/main.go
Or via docker compose:
docker compose run --rm golang go run /opt/project/cmd/02_get_from_a_queue/main.go
Now we will all be reading (consuming) messages of a queue. This application will keep running until you stop it with ctrl-c
.
go run cmd/03_consume_from_a_queue/main.go
Or via docker compose:
docker compose run --rm golang go run /opt/project/cmd/03_consume_from_a_queue/main.go
Yes? No? Why?
As seen in the presentation: "wie het eerst komt die het eerst maalt". We will now create our own (exclusive) queue in order to guarantee we receive all the data.
go run cmd/04_consume_all_messages_from_a_queue/main.go
Or via docker compose:
docker compose run --rm golang go run /opt/project/cmd/04_consume_all_messages_from_a_queue/main.go
Oh sorry, they are called "channels" actually and don't have the "routingkey" that RabbitMQ uses. However, you can still use it to shovel data around. Perhaps we want to parse our JSON string into an object. Possible that is an expensive operation, or maybe you just want to split off the logic. Now, consume from the amqp queue, log it, put the message on a channel and have another Go routine handle the parsing!
go run cmd/05_golang_also_has_queues/main.go
Or via docker compose:
docker compose run --rm golang go run /opt/project/cmd/05_golang_also_has_queues/main.go
Now you will be publishing your own message to the queue. Can you also read back this message by changing the routingkey in the code from step 4?
go run cmd/06_publish_to_an_exchange/main.go
Or via docker compose:
docker compose run --rm golang go run /opt/project/cmd/06_publish_to_an_exchange/main.go