golang编译-ldflags -H windowsgui被认为是病毒
go版本的supervisord

nats批量publish最后一条疑似丢失

妙音 posted @ 2021年11月14日 13:24 in golang with tags nats go , 1073 阅读
 

问题描述

 
    写了一个测试脚本,从数据读取一组数据,然后逐条publish到nats-server中, 确定每条都publish了
 
    有另外一个程序中subscribe订阅,在该程序发现最后一条一直没收到
 
 

环境

 
* go: 1.16
 
* nats-server
 

程序摘要

 
* 发布
 
for _, record := range records{
    ...
    gNatsConn.Publish(Topic, record)
    time.Sleep(time.Second*0.1)    //间隔越小出现的概率越大. 间隔1秒好像就没有
}
 
* 订阅
 
natsConn.Subscribe(topic, func(m *nats.Msg){
    fmt.Println(m.Data)
    ....
}
 

原因以及解决办法

 
    nats在发布消息时,有应该是用了缓存通道, 大小是1。最后一条数据有可能没被读走
 
    发布频率较高,最后需要flush一下
 
 
 
Avatar_small
sophia 说:
2023年6月21日 12:28

Interesting and amazing how your post is! It Is Useful and helpful for me That I like it very much, and I am looking forward to Hearing from your next.. 평택출장마사지

Avatar_small
SEO 说:
2023年7月13日 16:13

Very informative post! There is a lot of information here that can help any business get started with a successful social networking campaign. 천안출장마사지

Avatar_small
sophia 说:
2023年7月15日 22:17

I was surfing the Internet for information and came across your blog. I am impressed by the information you have on this blog. It shows how well you understand this subject. Clicksud

Avatar_small
six components of he 说:
2023年8月09日 16:42

Your writing always strikes a chord with me. This article is no exception.

Avatar_small
sophia 说:
2023年8月30日 12:42

Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you post again soon. Big thanks for the useful info. เว็บแทงบอลดีที่สุดUFABET

Avatar_small
Johny 说:
2023年9月01日 12:02

I really thank you for the valuable info on this great subject and look forward to more great posts. Thanks a lot for enjoying this beauty article with me. I am appreciating it very much! Looking forward to another great article. Good luck to the author! All the best! last minute naar larnaca

Avatar_small
sophia 说:
2023年9月23日 13:52

I was reading some of your content on this website and I conceive this internet site is really informative ! Keep on putting up. Fortune Mouse

Avatar_small
Johny 说:
2023年10月22日 14:26

I felt very happy while reading this site. This was really very informative site for me. I really liked it. This was really a cordial post. Thanks a lot!. ufabetทางเข้าเล่น

Avatar_small
asadullah 说:
2023年11月10日 17:14

Your blog is a one-stop-shop for all my recipe needs. I can always find something to suit my mood."

Avatar_small
tech 说:
2023年12月11日 23:38

The next time I read a blog, I hope that it doesn't disappoint me as much as this one. I mean, I know it was my choice to read, but I thought you had something interesting to say. All I hear is a bunch of whining about something that you could fix if you weren't too busy looking for attention. UFABETแทงบอลเว็บแม่

Avatar_small
johny 说:
2023年12月31日 13:17

Its a great pleasure reading your post.Its full of information I am looking for and I love to post a comment that "The content of your post is awesome" Great work. hi88

Avatar_small
johny 说:
2024年2月03日 16:49

You make so many great points here that I read your article a couple of times. Your views are in accordance with my own for the most part. This is great content for your readers. lingerie uae

Avatar_small
johny 说:
2024年2月08日 14:36

When you use a genuine service, you will be able to provide instructions, share materials and choose the formatting style. Cream chargers


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter