Connect to RabbitMQ in Go by dialing the server URL and publishing messages via an amqp091-go channel.
You connect to RabbitMQ in Go by importing github.com/streadway/amqp, dialing the server, and opening a channel to publish or consume messages.
import "github.com/streadway/amqp"
conn, err := amqp.Dial("amqp://guest:guest@localhost:5672/")
if err != nil { panic(err) }
defer conn.Close()
ch, err := conn.Channel()
if err != nil { panic(err) }
defer ch.Close()
err = ch.Publish("", "my-queue", false, false, amqp.Publishing{Body: []byte("Hello")})
if err != nil { panic(err) }
Using RabbitMQ in Go with amqp091-go connects your program to a message broker that acts like a digital post office for your applications. It opens a connection, creates a communication line, and sends a message to a specific queue for other services to pick up. Think of it as dropping a letter in a mailbox that a delivery person (another service) will retrieve and process later.