go-beanstalk是beanstalkd 的GO语言的一个客户端.
项目还在开发中,欢迎大家提意见
介绍
beanstalkd是一个快速的、有各种用途的延迟队列和定时任务的不同点:定时任务以一定的周期或者在某个特定的时间运行。beanstalk可以在延迟一段时间执行。一些使用场景:
用户下单5分钟后检查用户是否完成了支付一分钟后开始一个新的程序如何使用
Mac&Linux
安装并启动beantalkd服务器
gitclonehttps://github.com/kr/beanstalkdcdbeanstalkdmake./beanstalkd使用示例
gogetgithub.com/liuzhengyang/gobeanstalkcreateatest.gofile
packagemainimport("fmt""github.com/liuzhengyang/gobeanstalk")funcmain(){addr:="localhost:11300"//defineserveraddressnewConn:=gobeanstalk.NewConnection(addr)//createnewconnectionchannel:=make(chanint)//createintchannelputFunc:=func(){//defineafunctionwhichputsomemessagetoonetubeid,_:=newConn.PutWithTube("hello","test2",1)channel<-id}goputFunc()//runpreviousfunctioninago-routineid:=<-channel//waituntilwefinishputtingfmt.Printf("Receivefromchannelmessageofanothergoroutine%d\n",id)listenChannel:=make(chanstring)//makealistenchannelforreceivingresultsdealFunc:=func(bodystring)bool{//defineafunctiontodealwithtubemessagesfmt.Printf("receive%s\n",body)listenChannel<-bodyreturntrue}gonewConn.Listen("test2",dealFunc)//rundealfunctioninaspecifiedgo-routingbody:=<-listenChannel//waitourmessagefmt.Printf("Listenonce%s\n",body)newConn.Close()//Closeconnection}Andrunthis
goruntest.go
评论