1
0
mirror of https://github.com/eventials/goevents.git synced 2025-04-24 13:48:53 +08:00
eventials.goevents/amqp/producer.go
Alexandre Vicenzi 180f26f054 Add Docs.
2016-12-01 16:19:05 -02:00

34 lines
641 B
Go

package amqp
import (
"time"
"github.com/eventials/goevents/messaging"
amqplib "github.com/streadway/amqp"
)
type Producer struct {
conn *Connection
}
// NewProducer returns a new AMQP Producer.
func NewProducer(c messaging.Connection) (messaging.Producer, error) {
amqpConn := c.(*Connection)
return &Producer{
amqpConn,
}, nil
}
// Publish publishes an action.
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)
}