gobeanstalk [](<a href="https://github.com/liuzhengyang/gobeanstalk/blob/master/README-">https://github.com/liuzhengyang/gobeanstalk/blob/master/README-</a> 介绍
go-beanstalk 是beanstalkd 的GO语言的一个客户端.
项目还在开发中,欢迎大家提意见
[](https://github.com/liuzhengyang/gobeanstalk/blob/master/README-
zh_CN.md#介绍)介绍
beanstalkd是一个快速的、有各种用途的延迟队列 和定时任务的不同点:
定时任务以一定的周期或者在某个特定的时间运行。beanstalk可以在延迟一段时间执行。 一些使用场景:
[](https://github.com/liuzhengyang/gobeanstalk/blob/master/README-
zh_CN.md#如何使用)如何使用
[](https://github.com/liuzhengyang/gobeanstalk/blob/master/README-
zh_CN.md#maclinux)Mac&Linux
[](https://github.com/liuzhengyang/gobeanstalk/blob/master/README-
zh_CN.md#安装并启动beantalkd服务器)安装并启动beantalkd服务器
git clone https://github.com/kr/beanstalkd cd beanstalkd make ./beanstalkd
[](https://github.com/liuzhengyang/gobeanstalk/blob/master/README-
zh_CN.md#使用示例)使用示例
go get github.com/liuzhengyang/gobeanstalk
create a test.go file
package main import ( "fmt" "github.com/liuzhengyang/gobeanstalk" ) func main() { addr := "localhost:11300" // define server address newConn := gobeanstalk.NewConnection(addr) // create new connection channel := make(chan int) // create int channel putFunc := func() { // define a function which put some message to one tube id, _ := newConn.PutWithTube("hello", "test2", 1) channel <- id } go putFunc() // run prevIoUs function in a go-routine id := <-channel // wait until we finish putting fmt.Printf("Receive from channel message of another goroutine %d\n", id) listenChannel := make(chan string) // make a listen channel for receiving results dealFunc := func(body string) bool { // define a function to deal with tube messages fmt.Printf("receive %s\n", body) listenChannel <- body return true } go newConn.Listen("test2", dealFunc) // run deal function in a specified go-routing body := <-listenChannel // wait our message fmt.Printf("Listen once %s\n", body) newConn.Close() // Close connection }
And run this
go run test.go
gobeanstalk [](<a href="https://github.com/liuzhengyang/gobeanstalk/blob/master/README-">https://github.com/liuzhengyang/gobeanstalk/blob/master/README-</a> 官网
https://github.com/liuzhengyang/gobeanstalk
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。