forked from RichardKnop/machinery
/
rocketmq.go
50 lines (44 loc) · 1.25 KB
/
rocketmq.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
/**
* Created by Goland.
* Description:
* User: 礼凯
* Date: 2020/8/30 5:36 下午
*/
package common
import rocketmq "github.com/apache/rocketmq-client-go/core"
type ROCKETMQConnector struct{}
func (rc *ROCKETMQConnector) RocketmqConsumerConfig(url, group, accessKey, secretKey, channel string) *rocketmq.PushConsumerConfig {
pConfig := &rocketmq.PushConsumerConfig{
ClientConfig: rocketmq.ClientConfig{
GroupID: group,
NameServer: url,
Credentials: &rocketmq.SessionCredentials{
AccessKey: accessKey,
SecretKey: secretKey,
Channel: channel,
},
},
//设置使用集群模式。
Model: rocketmq.Clustering,
//设置该消费者为普通消息消费。
ConsumerModel: rocketmq.CoCurrently,
}
return pConfig
}
func (rc *ROCKETMQConnector) RocketmqProducerConfig(url, group, accessKey, secretKey, channel string) *rocketmq.ProducerConfig {
pConfig := &rocketmq.ProducerConfig{
ClientConfig: rocketmq.ClientConfig{
GroupID: group,
NameServer: url,
Credentials: &rocketmq.SessionCredentials{
AccessKey: accessKey,
SecretKey: secretKey,
Channel: channel,
},
},
// todo,不能写死
//主动设置该实例用于发送普通消息。
ProducerModel: rocketmq.CommonProducer,
}
return pConfig
}