Skip to content

Instantly share code, notes, and snippets.

@cheshir
Last active March 27, 2018 22:36
Show Gist options
  • Save cheshir/653b3c60903fcf42e60c0f6c14a9801e to your computer and use it in GitHub Desktop.
Save cheshir/653b3c60903fcf42e60c0f6c14a9801e 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