package main
|
|
|
|
import (
|
|
"log"
|
|
|
|
amqp "github.com/rabbitmq/amqp091-go"
|
|
rabbitmq "github.com/wagslane/go-rabbitmq"
|
|
)
|
|
|
|
func main() {
|
|
publisher, returns, err := rabbitmq.NewPublisher(
|
|
"amqp://guest:guest@localhost", amqp.Config{},
|
|
rabbitmq.WithPublisherOptionsLogging,
|
|
)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
err = publisher.Publish(
|
|
[]byte("hello, world"),
|
|
[]string{"routing_key"},
|
|
rabbitmq.WithPublishOptionsContentType("application/json"),
|
|
rabbitmq.WithPublishOptionsMandatory,
|
|
rabbitmq.WithPublishOptionsPersistentDelivery,
|
|
rabbitmq.WithPublishOptionsExchange("events"),
|
|
)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
go func() {
|
|
for r := range returns {
|
|
log.Printf("message returned from server: %s", string(r.Body))
|
|
}
|
|
}()
|
|
}
|