代码拉取完成,页面将自动刷新
package rabbitmq
import (
"context"
"gitee.com/lipore/plume/mq"
"github.com/pkg/errors"
"github.com/rabbitmq/amqp091-go"
)
type Publisher struct {
channel *amqp091.Channel
Exchange string
Key string
}
func (p *Publisher) Publish(ctx context.Context, body []byte) error {
err := p.channel.PublishWithContext(ctx, p.Exchange, p.Key, false, false, amqp091.Publishing{
ContentEncoding: "text/plain",
Body: body,
})
if err != nil {
return errors.WithMessage(err, "failed to publish message")
}
return nil
}
func NewPublisherFactory(connection *amqp091.Connection) mq.PublisherFactory {
return &PublisherFactory{
conn: connection,
}
}
type PublisherFactory struct {
conn *amqp091.Connection
}
func (p *PublisherFactory) NewPublisher(topic string) (mq.Publisher, error) {
channel, err := p.conn.Channel()
if err != nil {
return nil, errors.WithMessage(err, "failed to create channel")
}
return &Publisher{
channel: channel,
Exchange: topic,
Key: "",
}, nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。