Skip to content

Instantly share code, notes, and snippets.

@monkrus
Last active June 6, 2020 23:10
Show Gist options
  • Select an option

  • Save monkrus/283b457a6a5c246b2fe49962632a0b1b to your computer and use it in GitHub Desktop.

Select an option

Save monkrus/283b457a6a5c246b2fe49962632a0b1b to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"github.com/streadway/amqp"
)
func main() {
fmt.Println("Consumer Application")
conn, err := amqp.Dial("amqp://guest:guest@localhost:5672/")
if err != nil {
fmt.Println(err)
panic(err)
}
defer conn.Close()
ch, err := conn.Channel()
if err != nil {
fmt.Println(err)
panic(err)
}
defer ch.Close()
msgs, err := ch.Consume(
"TestQueue",
"",
true,
false,
false,
false,
nil,
)
forever := make(chan bool)
go func() {
for d := range msgs {
fmt.Printf("Received Message %s\n", d.Body)
}
}()
fmt.Println("Succesfully connected to our RabbitMQ instance")
fmt.Println(" [*] - waiting for messages")
<-forever
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment