如何从豆茎管中食用

How to consume from beanstalk tube

我正在使用 beantalk 将消息放入管中,我想从我将在运行时启动的新 EC2 实例中使用它。我可以将消息放入管中,但我无法以任何方式使用它。

我执行了以下步骤来测试:

文件:producer.py

#!/usr/bin/env python
import greenstalk
import json
import sys

beanstalkTube = 'tube-name'
beanstalkHost = 'host'
beanstalkPort = 11301

client = greenstalk.Client((beanstalkHost, beanstalkPort))
client.use(beanstalkTube)

client.put('message 1')

文件:consumer.py

#!/usr/bin/env python
import greenstalk
import json
import sys

beanstalkTube = 'tube-name'
beanstalkHost = 'host'
beanstalkPort = 11301

client = greenstalk.Client((beanstalkHost, beanstalkPort))
client.use(beanstalkTube)


job = client.reserve()

print("job_id:"+job.id)
print("job_body:"+job.body)

我还想知道的一件事是我应该如何使用 beantalk 通过 shell 脚本

将消息传递给新创建的 EC2 spot 实例

您将 use 一个用于放入消息的电子管。 从管中读取,你 watch 一个(或多个)管,当你调用 reserve 获取一个

时,服务器将 return 一条消息

Jobs will only be reserved from tubes on the watch list, which initially contains a single tube, default. You can add tubes to the watch list with watch and remove them with ignore. For convenience, it can be set with the watch argument when creating a Client. https://greenstalk.readthedocs.io/en/stable/quickstart.html#consuming-jobs