我创建了一个简单的脚本来使用 redis 测试 Dramatiq:
broker_redis = RedisBroker(host='localhost', port=6379)
@dramatiq.actor
def sq(x):
time.sleep(random.randint(2, 4))
return x * x
我正在使用此命令在 WSL 中运行(按照文档的规定):
dramatiq script_name:broker_redis
它运行没有任何错误,并在控制台上打印出这些行:
[2020-05-06 09:46:28,535] [PID 508] [MainThread] [dramatiq.MainProcess] [INFO] Dramatiq '1.8.1' is booting up.
[2020-05-06 09:46:28,535] [PID 511] [MainThread] [dramatiq.WorkerProcess(1)] [INFO] Worker process is ready for action.
[2020-05-06 09:46:28,546] [PID 510] [MainThread] [dramatiq.WorkerProcess(0)] [INFO] Worker process is ready for action.
[2020-05-06 09:46:28,548] [PID 544] [MainThread] [dramatiq.ForkProcess(0)] [INFO] Fork process 'dramatiq.middleware.prometheus:_run_exposition_server' is ready for action.
[2020-05-06 09:46:28,559] [PID 513] [MainThread] [dramatiq.WorkerProcess(3)] [INFO] Worker process is ready for action.
[2020-05-06 09:46:28,569] [PID 512] [MainThread] [dramatiq.WorkerProcess(2)] [INFO] Worker process is ready for action.
[2020-05-06 09:46:28,581] [PID 515] [MainThread] [dramatiq.WorkerProcess(5)] [INFO] Worker process is ready for action.
[2020-05-06 09:46:28,596] [PID 514] [MainThread] [dramatiq.WorkerProcess(4)] [INFO] Worker process is ready for action.
[2020-05-06 09:46:28,634] [PID 516] [MainThread] [dramatiq.WorkerProcess(6)] [INFO] Worker process is ready for action.
[2020-05-06 09:46:28,634] [PID 517] [MainThread] [dramatiq.WorkerProcess(7)] [INFO] Worker process is ready for action.
但是当我在解释器中导入这个函数并在它上面使用send
方法时......
from script_name import sq
sq.send(10)
...它等待几秒钟,然后引发dramatiq.errors.ConnectionClosed
错误:
dramatiq.errors.ConnectionClosed: AMQPConnectionError: (AMQPConnectorSocketConnectError: ConnectionRefusedError(10061, 'Unknown error'),)
似乎此调用无法将消息发送到在 WSL 中运行的 Dramatiq。
注意:我还没有安装 RabbitMQ,但如果我要使用 Redis,我认为它不是必需的。