Skip to content

Instantly share code, notes, and snippets.

@cheshir
Created March 28, 2018 13:17
Show Gist options
  • Save cheshir/50381517ddd0c4a1f7efabce5d099802 to your computer and use it in GitHub Desktop.
Save cheshir/50381517ddd0c4a1f7efabce5d099802 to your computer and use it in GitHub Desktop.
package main
import (
"github.com/cheshir/go-mq"
"gopkg.in/yaml.v2"
)
var externalConfiguration = []byte(`
{
"dsn": "amqp://guest:guest@localhost:5672/mq",
"exchanges": [
{
"name": "default",
"type": "direct",
"options": {
"durable": true
}
}
],
"queues": [
{
"name": "default",
"exchange": "default",
"routing_key": "route",
"options": {
"args": {
"x-max-priority": 9
},
"durable": true
}
}
],
"producers": [
{
"name": "default",
"routing_key": "route",
"exchange": "default"
}
]
}`)
func main() {
var config mq.Config
yaml.Unmarshal(externalConfiguration, &config)
rabbit, err := mq.New(config)
if err != nil {
panic("Error during mq initialization: " + err.Error())
}
go func() {
if err := <-rabbit.Error(); err != nil {
panic("Caught rmq error: "+err.Error())
}
}()
producer, err := rabbit.GetProducer("default")
if err != nil {
panic("Can't get producer: " + err.Error())
}
producer.Produce([]byte("some message"))
println("Message have sent. Check it in queue.")
rabbit.Close()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment