最新要闻

广告

手机

iphone11大小尺寸是多少?苹果iPhone11和iPhone13的区别是什么?

iphone11大小尺寸是多少?苹果iPhone11和iPhone13的区别是什么?

警方通报辅警执法直播中被撞飞:犯罪嫌疑人已投案

警方通报辅警执法直播中被撞飞:犯罪嫌疑人已投案

家电

通过随机数Random 和 redis的incr每次增加一的原子性来动态绑定队列

来源:博客园


【资料图】

通过随机数(1,4)和redis的incr每次增加一的原子性来动态绑定队列 队列:3个; pod:40个: 1. 通过随机数 Random().Next(1, 4)轮询每次返回 1,2,3 来达到一个消费端服务POD每次动态的绑定不同的队列 ,解决按开发者账号对应的渠道推送消息到queue1,queue2,queue3,消费端一套代码动态的绑定不同的队列消费, 缺点:到pod少时不够均衡 //int i = new Random().Next(1, 4); //string queue = "DirectExchangeQueue_"+ i; //string key = "key" + i;

2.通过redis inrc 类型来解决按开发者账号对应的渠道推送消息到queue1,queue2,queue3,消费端一套代码动态轮询均衡的绑定不同的队列消费 string rdisKey = CSRedisHelper.Get("meicardolare_incr_numer"); int queue_no = 0; if (string.IsNullOrEmpty(rdisKey)) { rdisKey = "0"; } else { queue_no = int.Parse(rdisKey); } Console.WriteLine("rdisKey:"+ queue_no);

string queue = "DirectExchangeQueue_"; string key = "key"; if (queue_no % 3 == 0) { queue = "DirectExchangeQueue_1"; key = "key1"; } else if (queue_no % 3 ==1) { queue = "DirectExchangeQueue_2"; key = "key2"; } else { queue = "DirectExchangeQueue_3"; key = "key3"; } Console.WriteLine("rdisKey:" + queue_no+ ";queue:" + queue+ ";key:"+ key);

CSRedisHelper.SetIncr("meicardolare_incr_numer");

DirectExchangeConsumerLogAll.TestManyQueue(key, queue);

test demo:

rdisKey:3900;queue:DirectExchangeQueue_1;key:key1rdisKey:3901rdisKey:3901;queue:DirectExchangeQueue_2;key:key2rdisKey:3902rdisKey:3902;queue:DirectExchangeQueue_3;key:key3rdisKey:3903rdisKey:3903;queue:DirectExchangeQueue_1;key:key1rdisKey:3904rdisKey:3904;queue:DirectExchangeQueue_2;key:key2rdisKey:3905rdisKey:3905;queue:DirectExchangeQueue_3;key:key3rdisKey:3906rdisKey:3906;queue:DirectExchangeQueue_1;key:key1rdisKey:3907rdisKey:3907;queue:DirectExchangeQueue_2;key:key2rdisKey:3908rdisKey:3908;queue:DirectExchangeQueue_3;key:key3rdisKey:3909rdisKey:3909;queue:DirectExchangeQueue_1;key:key1rdisKey:3910rdisKey:3910;queue:DirectExchangeQueue_2;key:key2rdisKey:3911rdisKey:3911;queue:DirectExchangeQueue_3;key:key3rdisKey:3912rdisKey:3912;queue:DirectExchangeQueue_1;key:key1rdisKey:3913rdisKey:3913;queue:DirectExchangeQueue_2;key:key2rdisKey:3914rdisKey:3914;queue:DirectExchangeQueue_3;key:key3rdisKey:3915rdisKey:3915;queue:DirectExchangeQueue_1;key:key1rdisKey:3916rdisKey:3916;queue:DirectExchangeQueue_2;key:key2rdisKey:3917rdisKey:3917;queue:DirectExchangeQueue_3;key:key3rdisKey:3918rdisKey:3918;queue:DirectExchangeQueue_1;key:key1rdisKey:3919rdisKey:3919;queue:DirectExchangeQueue_2;key:key2rdisKey:3920rdisKey:3920;queue:DirectExchangeQueue_3;key:key3rdisKey:3921rdisKey:3921;queue:DirectExchangeQueue_1;key:key1rdisKey:3922rdisKey:3922;queue:DirectExchangeQueue_2;key:key2rdisKey:3923rdisKey:3923;queue:DirectExchangeQueue_3;key:key3

关键词: