1
0
mirror of https://github.com/eventials/goevents.git synced 2025-05-11 19:29:17 +08:00
eventials.goevents/amqp/producer.go
2016-12-01 11:40:58 -02:00

32 lines
565 B
Go

package amqp
import (
"time"
"github.com/eventials/goevents/messaging"
amqplib "github.com/streadway/amqp"
)
type Producer struct {
conn *Connection
}
func NewProducer(c messaging.Connection) (messaging.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)
}