@@ -14,86 +14,99 @@ import (
1414// Configure secret_id, secret_key, region, and queue_name to run this example.
1515func main () {
1616
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 ,
3432 },
35- Password : "" ,
36- ConsumerGroup : "save_task_consumer_group" ,
37- Idle : 10 ,
3833 }
34+ queue_examples (option )
3935
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- }
4636 topicName := "pulsar-xxxxxx/namespace_name/topic_name"
4737 subscriptionName := "subscription_name"
4838 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 )
5048
51- optionForAWS := cloud. CommonOption {
49+ option = queue. QueueOption {
5250 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+ },
5657 }
57- queue_examples ("aws_queue_name" , optionForAWS )
58+
59+ queue_examples (option )
5860
5961 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 ,
6675 },
67- ConsumerGroup : "save_task_consumer_group_2" ,
68- DialTimeout : & dialTimeout ,
69- Idle : 10 ,
7076 },
7177 }
72- queue_examples ("redis_cluster_queue_v7" , clusterRedisQueueOptionV7 )
78+ queue_examples (option )
7379
7480 // 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+ },
8191 }
82- queue_examples ("mns_queue_name" , mnsQueueOption )
92+ queue_examples (option )
8393
8494 // 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 )
91104}
92105
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 )
95108 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 )
97110 return
98111 }
99112 defer service .Close ()
@@ -145,10 +158,10 @@ func queue_examples(queueOrTopicName string, option cloud.Option) {
145158}
146159
147160// 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 )
150163 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 )
152165 return
153166 }
154167 defer service .Close ()
0 commit comments