provider.go 451 B

123456789101112131415161718
  1. package Provider
  2. import "github.com/streadway/amqp"
  3. type Provider interface {
  4. MsgContent() string
  5. }
  6. func provide(channel *amqp.Channel, queue *amqp.Queue, msg string) error {
  7. //publishing为要发布的信息
  8. //Publishing的DeliveryMode如果设为amqp.Persistent则消息会持久化
  9. publishing := amqp.Publishing {
  10. ContentType: "text/plain",
  11. Body: []byte(msg),
  12. }
  13. return channel.Publish("", queue.Name,false,false, publishing)
  14. }