Skip to Content
Go Realm v1 is released 🎉
RabbitMQDay 2: Setup and First Go App

Day 2

Local Setup and First Go Producer/Consumer

āφāϜāϕ⧇ āφāĻŽāϰāĻž RabbitMQ locally run āĻ•āϰāĻŦ, management UI āĻĻ⧇āĻ–āĻŦ, āĻāĻŦāĻ‚ Go āĻĻāĻŋā§Ÿā§‡ first publish-consume cycle āϞāĻŋāĻ–āĻŦāĨ¤

Setup Checklist

StepCommand / ActionExpected
1docker run -d --hostname rabbit-dev --name rabbit-dev -p 5672:5672 -p 15672:15672 rabbitmq:3-managementRabbitMQ container up
2Browser āϖ⧁āϞ⧇ http://localhost:15672UI open
3Login with guest / guestdashboard āĻĻ⧇āĻ–āĻžāĻŦ⧇
4go get github.com/rabbitmq/amqp091-gopackage ready
msgs, err := ch.Consume("hello.queue", "", true, false, false, false, nil) if err != nil { log.Fatal(err) } for msg := range msgs { log.Printf("received: %s", msg.Body) }
err = ch.Publish("", "hello.queue", false, false, amqp.Publishing{ ContentType: "text/plain", Body: []byte("hello rabbitmq from go"), }) if err != nil { log.Fatal(err) }

Predict the Output

Situation: Consumer āφāϗ⧇ āϚāĻžāϞ⧁ āφāϛ⧇āĨ¤ āϤāĻžāϰāĻĒāϰ producer āĻāĻ•āĻŦāĻžāϰ āϚāĻžāϞāĻžāύ⧋ āĻšāϞ⧋āĨ¤

Goal: Console-āĻ āϕ⧀ āĻšāĻŦ⧇?

What to think about:

  • Queue āφāϗ⧇ āĻĨ⧇āϕ⧇āχ declared
  • Consumer auto-ack mode-āĻ āφāϛ⧇
  • One message published āĻšā§Ÿā§‡āϛ⧇
āϏāĻŽā§āĻ­āĻžāĻŦā§āϝ āϏāĻŽāĻžāϧāĻžāύ āĻĻ⧇āϖ⧁āύ

Consumer console-āĻ `received: hello rabbitmq from go` āϟāĻžāχāĻĒ āφāωāϟāĻĒ⧁āϟ āĻĻ⧇āĻ–āĻž āϝāĻžāĻŦ⧇, āĻāĻŦāĻ‚ queue depth āφāĻŦāĻžāϰ zero āĻšā§Ÿā§‡ āϝāĻžāĻŦ⧇āĨ¤

āφāϜāϕ⧇āϰ production note

Checkpoint

āύāĻŋāĻœā§‡ explain āĻ•āϰ⧋: producer āφāϰ consumer āωāϭ⧟ code-āĻ `QueueDeclare` āϕ⧇āύ āĻĨāĻžāĻ•āϤ⧇ āĻĒāĻžāϰ⧇?

  • Idempotent topology setup āĻšāĻŋāϏ⧇āĻŦ⧇
  • Service startup-āĻ dependency reduce āĻ•āϰāϤ⧇
  • āĻ•āĻŋāĻ¨ā§āϤ⧁ parameters mismatch āĻšāϞ⧇ error āφāϏāϤ⧇ āĻĒāĻžāϰ⧇