項目還在開發中,歡迎你們提意見git
beanstalkd是一個快速的、有各類用途的延遲隊列 和定時任務的不一樣點: 定時任務以必定的週期或者在某個特定的時間運行。beanstalk能夠在延遲一段時間執行。 一些使用場景:github
git clone https://github.com/kr/beanstalkd cd beanstalkd make ./beanstalkd
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 thisthis
go run test.go