-
-
Save monkrus/d1369465348512380ceb89db3e6daf5f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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