dongliu4320 2015-07-05 15:57
浏览 73
已采纳

可能/建议在Go中编写事件驱动的应用程序?

I am designing an app to manage RabbitMQ workers given certain rules. For example:

  • Maintain a minimum number of workers
  • Spawn up to N max number of workers if queue grows beyond M tasks
  • Kill workers older than X minutes

I originally thought of writing it in Go because it is compiled & I could simply compile the app to the target OS & daemonize it. However, my concept design involves having a loop that gathers data every Y seconds & passes it through a decision engine. The engine would then raise events that would be listened to by other goroutines to either spawn or kill workers.

I've found the Emission library which would acommodate this, but I read a comment somewhere that it might not be thread safe. Honestly, my knowledge of Go & threaded programming are not sufficient to properly evaluate if this library would accomplish what I need or if this is even possible in Go.

I could write this very quickly in NodeJS and even get it compiled using nexe. However, I wanted to learn a new language, I liked the targeted compilation in Go, and that it can be multi-threaded beyond the goroutines themselves.

Is this possible or am I trying to shoehorn something into Go that it wasn't designed to do? Would it be better to accomplish the same goals differently or to just use a different language all together?

  • 写回答

2条回答 默认 最新

  • duanhong1985 2015-07-10 20:42
    关注

    I had not seen Emission library before which could work very neatly to send different messages to your workers. This could also be achieved by using channels which would be a more flexible implementation but also more cumbersome if you do not know the language.

    I would certainly read on channels but be very careful as broadcasting through channels is not straightforward. Take a look at this example (https://rogpeppe.wordpress.com/2009/12/01/concurrent-idioms-1-broadcasting-values-in-go-with-linked-channels/)

    Overall I would take a look at Tunny (https://github.com/Jeffail/tunny) to manage workers it already has most of the implementation done for you.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 C语言设计一个简单的自动换档程序
  • ¥15 关于logstash转发日志时发生的部分内容丢失问题
  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。