@@ -14,86 +14,99 @@ import (
14
14
// Configure secret_id, secret_key, region, and queue_name to run this example.
15
15
func main () {
16
16
17
- // Redis 单节点
18
- //optionForBaseRedis := queue.StandaloneRedisQueueOption{
19
- // Addr: "localhost:6379",
20
- // Password: "",
21
- // ConsumerGroup: "save_task_consumer_group",
22
- // Idle: 10,
23
- //}
24
-
25
- // Redis 集群
26
- optionForBaseRedis := queue.ClusterRedisQueueOption {
27
- Addrs : []string {
28
- "localhost:7000" ,
29
- "localhost:7001" ,
30
- "localhost:7002" ,
31
- "localhost:7003" ,
32
- "localhost:7004" ,
33
- "localhost:7005" ,
17
+ option := queue.QueueOption {
18
+ Provider : cloud .ClusterRedisProvider ,
19
+ QueueName : "test_queue_name" ,
20
+ ClusterRedis : queue.ClusterRedisQueueOption {
21
+ Addrs : []string {
22
+ "localhost:7000" ,
23
+ "localhost:7001" ,
24
+ "localhost:7002" ,
25
+ "localhost:7003" ,
26
+ "localhost:7004" ,
27
+ "localhost:7005" ,
28
+ },
29
+ Password : "" ,
30
+ ConsumerGroup : "save_task_consumer_group" ,
31
+ Idle : 10 ,
34
32
},
35
- Password : "" ,
36
- ConsumerGroup : "save_task_consumer_group" ,
37
- Idle : 10 ,
38
33
}
34
+ queue_examples (option )
39
35
40
- queue_examples ("test_queue_name" , optionForBaseRedis )
41
-
42
- optionForTencentCloud := queue.TencentCloudQueueOption {
43
- Token : "access_jwt_token_xxx" ,
44
- URL : "http://pulsar-xxxxxxxxx.tdmq.ap-gz.public.tencenttdmq.com:8080" ,
45
- }
46
36
topicName := "pulsar-xxxxxx/namespace_name/topic_name"
47
37
subscriptionName := "subscription_name"
48
38
topicSub := queue .GenerateTopicAndSubName (topicName , subscriptionName )
49
- queue_examples (topicSub , optionForTencentCloud )
39
+ option = queue.QueueOption {
40
+ Provider : cloud .TencentCloudProvider ,
41
+ QueueName : topicSub ,
42
+ Pulsar : queue.TencentCloudQueueOption {
43
+ Token : "access_jwt_token_xxx" ,
44
+ URL : "http://pulsar-xxxxxxxxx.tdmq.ap-gz.public.tencenttdmq.com:8080" ,
45
+ },
46
+ }
47
+ queue_examples (option )
50
48
51
- optionForAWS := cloud. CommonOption {
49
+ option = queue. QueueOption {
52
50
Provider : cloud .AWSProvider ,
53
- SecretID : "aws_secret_id_xxxx" ,
54
- SecretKey : "aws_secret_key_xxxx" ,
55
- Region : "aws_region_xxx" ,
51
+ QueueName : "aws_queue_name" ,
52
+ SQS : cloud.AWSOption {
53
+ SecretID : "aws_secret_id_xxxx" ,
54
+ SecretKey : "aws_secret_key_xxxx" ,
55
+ Region : "aws_region_xxx" ,
56
+ },
56
57
}
57
- queue_examples ("aws_queue_name" , optionForAWS )
58
+
59
+ queue_examples (option )
58
60
59
61
dialTimeout := 5 * time .Second
60
- clusterRedisQueueOptionV7 := queue.ClusterRedisQueueOptionV7 {
61
- ClusterRedisQueueOption : queue.ClusterRedisQueueOption {
62
- Addrs : []string {
63
- "localhost:30001" ,
64
- "localhost:30002" ,
65
- "localhost:30003" ,
62
+ option = queue.QueueOption {
63
+ Provider : cloud .ClusterRedisProviderV7 ,
64
+ QueueName : "redis_cluster_queue_v7" ,
65
+ ClusterRedisV7 : queue.ClusterRedisQueueOptionV7 {
66
+ ClusterRedisQueueOption : queue.ClusterRedisQueueOption {
67
+ Addrs : []string {
68
+ "localhost:30001" ,
69
+ "localhost:30002" ,
70
+ "localhost:30003" ,
71
+ },
72
+ ConsumerGroup : "save_task_consumer_group_2" ,
73
+ DialTimeout : & dialTimeout ,
74
+ Idle : 10 ,
66
75
},
67
- ConsumerGroup : "save_task_consumer_group_2" ,
68
- DialTimeout : & dialTimeout ,
69
- Idle : 10 ,
70
76
},
71
77
}
72
- queue_examples ("redis_cluster_queue_v7" , clusterRedisQueueOptionV7 )
78
+ queue_examples (option )
73
79
74
80
// alicloud MNS queue: access_key CredentialType
75
- mnsQueueOption := queue.AliMNSClientOption {
76
- EndPoint : "http://account-id.mns.region.aliyuncs.com" ,
77
- CredentialType : cloud .AliCloudAccessKeyCredentialType ,
78
- AccessKeyId : "alicloud_access_key_id" ,
79
- AccessKeySecret : "alicloud_access_key_secret" ,
80
- MessagePriority : 10 ,
81
+ option = queue.QueueOption {
82
+ Provider : cloud .AliCloudProvider ,
83
+ QueueName : "mns_queue_name" ,
84
+ MNS : queue.AliMNSClientOption {
85
+ EndPoint : "http://account-id.mns.region.aliyuncs.com" ,
86
+ CredentialType : cloud .AliCloudAccessKeyCredentialType ,
87
+ AccessKeyId : "alicloud_access_key_id" ,
88
+ AccessKeySecret : "alicloud_access_key_secret" ,
89
+ MessagePriority : 10 ,
90
+ },
81
91
}
82
- queue_examples ("mns_queue_name" , mnsQueueOption )
92
+ queue_examples (option )
83
93
84
94
// alicloud MNS queue: ecs_ram_role credentialType
85
- mnsQueueOption = queue.AliMNSClientOption {
86
- EndPoint : "http://account-id.mns.region.aliyuncs.com" ,
87
- CredentialType : cloud .AliCloudECSRamRoleCredentialType ,
88
- }
89
- queue_examples ("mns_queue_name" , mnsQueueOption )
90
- alicloud_mns_queue_examples ("mns_queue_name" , mnsQueueOption )
95
+ option = queue.QueueOption {
96
+ Provider : cloud .AliCloudProvider ,
97
+ QueueName : "mns_queue_name" ,
98
+ MNS : queue.AliMNSClientOption {
99
+ EndPoint : "http://account-id.mns.region.aliyuncs.com" ,
100
+ CredentialType : cloud .AliCloudECSRamRoleCredentialType ,
101
+ }}
102
+ queue_examples (option )
103
+ alicloud_mns_queue_examples (option )
91
104
}
92
105
93
- func queue_examples (queueOrTopicName string , option cloud. Option ) {
94
- service , err := queue .GetQueueService ( queueOrTopicName , option )
106
+ func queue_examples (option queue. QueueOption ) {
107
+ service , err := queue .GetQueueServiceWithOption ( option )
95
108
if err != nil {
96
- fmt .Printf ("get queue service error %s %+v %s\n " , queueOrTopicName , option , err )
109
+ fmt .Printf ("get queue service error %s %+v %s\n " , option . QueueName , option , err )
97
110
return
98
111
}
99
112
defer service .Close ()
@@ -145,10 +158,10 @@ func queue_examples(queueOrTopicName string, option cloud.Option) {
145
158
}
146
159
147
160
// The following examples show mns queue specific examples: How to set message priority; how to set long polling period seconds.
148
- func alicloud_mns_queue_examples (queueOrTopicName string , option cloud. Option ) {
149
- service , err := queue .GetQueueService ( queueOrTopicName , option )
161
+ func alicloud_mns_queue_examples (option queue. QueueOption ) {
162
+ service , err := queue .GetQueueServiceWithOption ( option )
150
163
if err != nil {
151
- fmt .Printf ("get queue service error %s %+v %s\n " , queueOrTopicName , option , err )
164
+ fmt .Printf ("get queue service error %s %+v %s\n " , option . QueueName , option , err )
152
165
return
153
166
}
154
167
defer service .Close ()
0 commit comments