Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save monkrus/d1369465348512380ceb89db3e6daf5f to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"github.com/streadway/amqp"
)
func main() {
fmt.Println("Go RabbitMQ Tutorial")
conn, err := amqp.Dial("amqp://guest:guest@localhost:5672/")
if err != nil {
fmt.Println(err)
panic(err)
}
defer conn.Close()
fmt.Println("Succesfully Connected To our RabbitMQ Instance")
ch, err := conn.Channel()
if err != nil {
fmt.Println(err)
panic(err)
}
defer ch.Close()
q, err := ch.QueueDeclare(
"TestQueue",
false,
false,
false,
false,
nil,
)
if err != nil {
fmt.Println(err)
panic(err)
}
fmt.Println(q)
err = ch.Publish(
"",
"TestQueue",
false,
false,
amqp.Publishing{
ContentType: "text/plain",
Body: []byte("Hello World"),
},
)
if err != nil {
fmt.Println(err)
panic(err)
}
fmt.Println("Succesfully Published Message to Queue")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment