我在 LocalStack 服务器上有一个 SQS 队列,我正在尝试使用 Celery 消费者从中获取消息。
它表明消费者已正确附加到队列,例如队列,但是当我尝试使用命令sqs-test-queue
发送消息时它没有收到任何消息。aws
我的celeryconfig.py
样子是这样的:
from kombu import (
Exchange,
Queue
)
broker_transport_options = {'region': REGION}
broker_transport = 'sqs'
accept_content = ['application/json']
result_serializer = 'json'
content_encoding = 'utf-8'
task_serializer = 'json'
worker_enable_remote_control = False
worker_send_task_events = False
result_backend = None
task_queues = (
Queue('sqs-test-queue', exchange=Exchange(''), routing_key='sqs-test-queue'),
)
我的tasks.py
模块看起来像这样:
from celery import Celery
from kombu.utils.url import quote
AWS_ACCESS_KEY = quote("AWS_ACCESS_KEY")
AWS_SECRET_KEY = quote("AWS_SECRET_KEY")
LOCALSTACK = "<IP>:<PORT>"
broker_url = "sqs://{access}:{secret}@{host}".format(access=AWS_ACCESS_KEY,
secret=AWS_SECRET_KEY,
host=LOCALSTACK)
app = Celery('tasks', broker=broker_url, backend=None)
app.config_from_object('celeryconfig')
@app.task(bind=True, name='tasks.consume', acks_late=True, ignore_result=True)
def consume(self, msg):
# DO SOMETHING WITH THE RECEIVED MESSAGE
return True
试图用它来执行它,celery -A tasks worker -l INFO -Q sqs-test-queue
一切都很好:
...
[tasks]
. tasks.consume
[... INFO/MainProcess] Connected to sqs://AWS_ACCESS_KEY:**@<IP>:<PORT>//
[... INFO/MainProcess] celery@local ready
但是当我尝试用 发送消息时aws sqs send-message --endpoint-url=http://<IP>:<PORT> --queue-url=http://localhost:<PORT>/queue/sqs-test-queue --message-body="Test message"
,什么也没有发生。
我究竟做错了什么?我是否错过了配置中的某些内容?
PS:如果我尝试运行命令aws sqs receive-message --endpoint-url=http://<IP>:<PORT> --queue-url=http://localhost:<PORT>/queue/sqs-test-queue
,我可以得到消息。
笔记:
我正在使用Python 3.7.0
,我的pip freeze
样子是这样的:
boto3==1.10.16
botocore==1.13.16
celery==4.3.0
kombu==4.6.6
pycurl==7.43.0.3
...