1
0
mirror of https://github.com/eventials/goevents.git synced 2025-04-24 13:48:53 +08:00
eventials.goevents/amqp/producer.go
2016-12-01 10:52:22 -02:00

31 lines
549 B
Go

package amqp
import (
"time"
base "github.com/eventials/goevents"
amqplib "github.com/streadway/amqp"
)
type Producer struct {
conn *Connection
}
func NewProducer(c base.Connection) (base.Producer, error) {
amqpConn := c.(*Connection)
return &Producer{
amqpConn,
}, nil
}
func (p *Producer) Publish(action string, data []byte) error {
msg := amqplib.Publishing{
DeliveryMode: amqplib.Persistent,
Timestamp: time.Now(),
Body: data,
}
return p.conn.channel.Publish(p.conn.exchangeName, action, false, false, msg)
}