有 3 台机器和 1 个发布者,2 个消费者。我正在使用 golang 将订单发布到某台机器。并且机器使用python作为消费者。我想知道如何在发布者中获得订单完成或失败的结果。
如果订单不属于机器一,我该怎么办?释放还是埋葬它?
蟒蛇:消费者:
import beanstalkc
def get_beanstalk_data(conf):
beanstalk = beanstalkc.Connection(host='127.0.0.1',port=11300)
beanstalk.use('cloud')
beanstalk.watch('cloud')
beanstalk.ignore('default')
job = beanstalk.reserve()
if job.body == "one": #job.body == "two"
#TODO
job.delete()
return job.body
else:
#TODO what should I do in here, because there is two consumer and get different orders
while True:
data = get_beanstalk_data(conf)
print data
golang:发布:
package main
import (
"fmt"
"github.com/kr/beanstalk"
"time"
)
func main() {
c, err := beanstalk.Dial("tcp", "127.0.0.1:11300")
id, err := c.Put([]byte("hello"), 1, 0, 120*time.Second)
if err != nil {
fmt.Println(err)
}
fmt.Println(id)
}