36 lines
598 B
Go
36 lines
598 B
Go
package mq
|
|
|
|
import (
|
|
"context"
|
|
"trasfer_middleware/until/mq"
|
|
)
|
|
|
|
type RocketMq struct {
|
|
}
|
|
|
|
type AliyunRocketMq struct {
|
|
AccessKey string
|
|
SecretKey string
|
|
SecurityToken string
|
|
ServerAddress []string
|
|
}
|
|
|
|
func (n *AliyunRocketMq) Produce(c context.Context, topic string, body []byte) error {
|
|
|
|
p, err := mq.NewProducer(n.ServerAddress[0], mq.WithProducerCredentials(n.AccessKey, n.SecretKey, n.SecurityToken))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
err = p.Start()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
err = p.SendSync(c, topic, body)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
p.Shutdown()
|
|
|
|
return nil
|
|
}
|