有三台机器,一台出版商,两位消费者。我正在用金刚向某台机器发布订单。这台机器是用巨蟒做消费者的。我想知道如何才能得到订单在publisher中已经完成或失败的结果。
如果订单不属于机器一号,我该怎么办?放了还是埋了?
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戈朗:出版:
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)
}发布于 2016-12-26 06:03:39
让发布者知道作业状态的正确方法是使用回调。
在作业中,让发布者放置回调url (队列或http),在作业成功或失败时,使用者可以向状态回调发送状态消息。
因此,工作结构可能会隐约出现
//JobRequest has the struct storing request name and body
type JobRequest struct {
ID string
RequestBody []byte
CallbackURL *string
}上述结构的json字符串将是body.The使用者将获得CallbackURL并将状态感测到该url的作业。
试图解释为需要解释的细节
让我们打电话给producer和consumer(s),master和workers(s)。
- job id (A unique value to identify teh job)
- RequestBody (The details of the job)
- StatusCallbackURL (URL the worker would hit with the job status)
reserve工作的工人说我要去做这份工作。delete中,任务从队列发送到CallbackURLdelete作业,则为失败现在,这个对象被转换为json并放入队列。
PS:在成功完成.On完成或永久失败之前不删除作业,只删除作业
https://stackoverflow.com/questions/41326122
复制相似问题