You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

37 lines
824 B

package main
import (
"log"
rabbitmq "github.com/wagslane/go-rabbitmq"
)
func main() {
consumer, err := rabbitmq.NewConsumer(
"amqp://guest:guest@localhost",
rabbitmq.WithConsumerOptionsLogging,
)
if err != nil {
log.Fatal(err)
}
err = consumer.StartConsuming(
func(d rabbitmq.Delivery) bool {
log.Printf("consumed: %v", string(d.Body))
// true to ACK, false to NACK
return true
},
"my_queue",
[]string{"routing_key", "routing_key_2"},
rabbitmq.WithConsumeOptionsConcurrency(10),
rabbitmq.WithConsumeOptionsQueueDurable,
rabbitmq.WithConsumeOptionsQuorum,
rabbitmq.WithConsumeOptionsBindingExchange("events", "topic", true, false, false, true, nil),
)
if err != nil {
log.Fatal(err)
}
// block main thread so consumers run forever
forever := make(chan struct{})
<-forever
}