1
0
mirror of https://github.com/eventials/goevents.git synced 2025-04-28 13:48:49 +08:00
eventials.goevents/producer.go

28 lines
447 B
Go
Raw Normal View History

2016-11-25 18:51:34 -02:00
package main
import (
"time"
"github.com/streadway/amqp"
)
type Producer struct {
conn *Connection
}
func NewProducer(c *Connection) *Producer {
return &Producer{
c,
}
}
2016-11-28 15:08:56 -02:00
func (p *Producer) Publish(action string, data []byte) error {
2016-11-25 18:51:34 -02:00
msg := amqp.Publishing{
DeliveryMode: amqp.Persistent,
Timestamp: time.Now(),
Body: data,
}
2016-11-28 15:08:56 -02:00
return p.conn.channel.Publish(p.conn.exchangeName, action, false, false, msg)
2016-11-25 18:51:34 -02:00
}