Go works with message queues via client libraries.
1// NATS: high-performance queue2import "github.com/nats-io/nats.go"34// Connect5nc, err := nats.Connect("nats://localhost:4222")6if err != nil {7 log.Fatal(err)8}9def nc.Close()1011// Publish12nc.Publish("orders.new", []byte(`{"id": 1, "amount": 100}`))1314// Subscribe15nc.Subscribe("orders.new", func(msg *nats.Msg) {16 fmt.Printf("Received: %s\n", string(msg.Data))17})1819// Request/Response20reply, err := nc.Request("orders.get", []byte(`{"id": 1}`), 5*time.Second)21fmt.Println(string(reply.Data))2223// JetStream: persistent queue24js, _ := nc.JetStream()25js.Publish("orders.new", data)2627// RabbitMQ28import amqp "github.com/rabbitmq/amqp091-go"2930conn, _ := amqp.Dial("amqp://guest:guest@localhost:5672/")31ch, _ := conn.Channel()3233// Queue declaration34q, _ := ch.QueueDeclare("orders", true, false, false, false, nil)3536// Publish37ch.Publish("", q.Name, false, false, amqp.Publishing{38 ContentType: "application/json",39 Body: []byte(`{"id": 1}`),40})4142// Consume43msgs, _ := ch.Consume(q.Name, "", false, false, false, false, nil)44for msg := range msgs {45 fmt.Printf("Received: %s\n", msg.Body)46 msg.Ack(false)47}
NATS vs RabbitMQ: