I just started reading about RabbitMQ
and I'm trying to send large number of messages in a for loop. The problem is that it just doesn't work.
package main
import (
"fmt"
"github.com/streadway/amqp"
"strconv"
)
func main() {
var connectionString = "amqp://guest:guest@localhost:5672/"
conn, _ := amqp.Dial(connectionString)
defer conn.Close()
ch, _ := conn.Channel()
defer ch.Close()
q, _ := ch.QueueDeclare(
"user_actions", // name
true, // durable
false, // delete when unused
false, // exclusive
false, // no-wait
nil, // arguments
)
for i := 0; i < 10000; i++ {
body := "Hello from Go! " + strconv.Itoa(i)
ch.Publish(
"", // exchange
"hello", // routing key
false, // mandatory
false, // immediate
amqp.Publishing {
ContentType: "text/plain",
Body: []byte(body),
})
fmt.Println("Sent: "+body)
}
}
I even tried reducing the number of iterations and even tried sending messages outside of the loop but it just doesn't work. What am I doing wrong?