-
Notifications
You must be signed in to change notification settings - Fork 3
/
producer.go
58 lines (50 loc) · 1.33 KB
/
producer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package rocketmq5Kit
import (
"context"
rmq_client "github.com/apache/rocketmq-clients/golang/v5"
)
// NewProducer
/*
@param logConfig 可以为nil
@return rmq_client.Producer实例要手动调用 Start()!!!
*/
func NewProducer(logConfig *LogConfig, config *rmq_client.Config) (rmq_client.Producer, error) {
lock.Lock()
defer lock.Unlock()
if err := logConfig.SetLogout(); err != nil {
return nil, err
}
config, err := processConfig(config)
if err != nil {
return nil, err
}
return rmq_client.NewProducer(config)
}
// SendMessage
/*
Deprecated: 此方法仅供参考.
@param tag 可以为nil
*/
func SendMessage(producer rmq_client.Producer, topic string, body []byte, tag *string, keys ...string) (*rmq_client.SendReceipt, error) {
respSlice, err := SendMessageForSendReceipts(producer, topic, body, tag, keys...)
if err != nil {
return nil, err
}
// SimpleConsumer + Producer的情况下,响应的长度为1
return respSlice[0], nil
}
// SendMessageForSendReceipts
/*
Deprecated: 此方法仅供参考.
*/
func SendMessageForSendReceipts(producer rmq_client.Producer, topic string, body []byte, tag *string, keys ...string) ([]*rmq_client.SendReceipt, error) {
msg := &rmq_client.Message{
Topic: topic,
Body: body,
}
if tag != nil {
msg.SetTag(*tag)
}
msg.SetKeys(keys...)
return producer.Send(context.TODO(), msg)
}