message-queue-workshop

module
v0.0.0-...-b0bad55 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2025 License: GPL-3.0

README

Message Queue Workshop

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 follow this readme or open it via GitHub Pages

Prerequisites

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.24 or newer (older versions will probably work too, but we recommend using the latest version)
  • 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.24 or newer
  • 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

Step 1: Hello World

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

Step 2: Getting a message from a queue

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

Step 3: Consuming from a queue

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

Question: Does everybody get all the data?

Yes? No? Why?

Step 4: Getting all the data

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

Step 5: Golang also has queues

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

Step 6: Publishing!

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

Directories

Path Synopsis
cmd
05_golang_also_has_queues
Ok I lied, they are not queues but channels :)
Ok I lied, they are not queues but channels :)
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL