- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在尝试让我正在处理的项目的结果后端在我的本地机器上运行,但我遇到了问题。
目前,我正在尝试创建一个队列系统,以便我的实验室创建案例。这是为了防止使用重复的序列号。我已经在使用 Celery 进行打印,所以我想我会创建一个新的 Celery 队列并使用它来处理这个问题。前端还需要获取创建案例的结果,以显示创建的案例编号。
http://docs.celeryproject.org/en/latest/getting-started/first-steps-with-celery.html#rabbitmq
我正在按照上面的教程配置我的 Celery。以下是来源:
celeryconfig.py:
from kombu import Queue
CELERY_DEFAULT_QUEUE = 'celery'
CELERY_DEFAULT_EXCHANGE = 'celery'
CELERY_DEFAULT_EXCHANGE_TYPE = 'direct'
CELERY_RESULT_BACKEND = 'rpc://'
CELERY_RESULT_PERSISTENT = False
CELERY_QUEUES = (
Queue('celery', routing_key="celery"),
Queue('case_creation', routing_key='create.#')
)
CELERY_ROUTES = {
'case.tasks.create_case': {
'queue': 'case_creation',
'routing_key': 'create.1'
},
'print.tasks.connect_and_serve': {
'queue': 'celery',
'routing_key': 'celery'
}
}
celery .py:
import os
from celery import Celery
from django.conf import settings
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'proj.settings.local')
app = Celery('proj', broker='amqp://guest@localhost//')
app.config_from_object('proj.celeryconfig')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
任务.py:
import celery
from django.db import IntegrityError
from case.case_create import CaseCreate
@celery.task(bind=True)
def create_case(self, data, user, ip):
try:
acc = CaseCreate(data, user, ip)
return acc.begin()
except IntegrityError as e:
self.retry(exc=e, countdown=2)
这是我调用上述任务的 View :
@require_authentication()
@requires_api_signature()
@csrf_exempt
@require_http_methods(['POST'])
def api_create_case(request):
result = create_case.delay(json.loads(request.body.decode('utf-8')), request.user, get_ip_address(request))
print(str(result)) # Prints the Task ID
print(str(result.get(timeout=1))) # Throws error
return HttpResponse(json.dumps({'result': str(result)}), status=200)
我使用以下命令启动我的 celery 队列:
celery -A proj worker -Q case_creation -n case_worker -c 1
当我运行 celery worker 时,我确实看到结果显示在配置下:
-------------- celery@case_worker v3.1.16 (Cipater)
---- **** -----
--- * *** * -- Windows-8-6.2.9200
-- * - **** ---
- ** ---------- [config]
- ** ---------- .> app: proj:0x32a2990
- ** ---------- .> transport: amqp://guest:**@localhost:5672//
- ** ---------- .> results: rpc://
- *** --- * --- .> concurrency: 1 (prefork)
-- ******* ----
--- ***** ----- [queues]
-------------- .> case_creation exchange=celery(direct) key=create.#
当我运行程序并提交新案例时,这是我收到的错误消息:
No result backend configured. Please see the documentation for more information.
我已经尝试了所有可以在网上找到的东西。有没有人可以指出我正确的方向?我非常接近并且非常厌倦查看这段代码。
最佳答案
如果你想保留你的结果,试试这个 Keeping Results
app = Celery('proj', backend='amqp', broker='amqp://guest@localhost//')
Make sure the client is configured with the right backend.
If for some reason the client is configured to use a different backend than the worker, you will not be able to receive the result, so make sure the backend is correct by inspecting it:
试试看输出:
>>> result = task.delay(…)
>>> print(result.backend)
其他解决方案将代替
app = Celery('proj',
backend='amqp',
broker='amqp://',
include=['proj.tasks'])
尝试:
app = Celery('proj',
broker='amqp://',
include=['proj.tasks'])
app.conf.update(
CELERY_RESULT_BACKEND='amqp'
)
关于python - 在 Django 中使用 Celery 设置结果后端 (rpc),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39459290/
RPC 在消息传递方面的缺点是什么? 最佳答案 您是在谈论 RPC 与消息传递吗?就像(通常)异步消息传递一样?如果这就是您所说的,那么消息传递往往会以复杂性和额外基础架构为代价变得更加健壮。 最简单
我想查看不在我钱包中的btc地址余额。似乎像 blockchainexplorer 这样的网站会做这类事情。他们还提供 API,但我遇到了他们的 API 使用限制。所以我下载了完整的区 block 链
我想获得这样的 RPC 信息: > show route output interface ae40.4181 | display xml rpc
我从我的 javascript 发送交易 Metamask 打开传输对话框 我确定 i get an error message in metamask (inpage.js:1 MetaMask -
有一个场景,客户端通过 RPC 触发 cordapp 并等待结果。 rpcConnection.proxy .startFlow(::ImportAssetFlow, importDto) .retu
super 简单的问题,我在那里找不到具体的答案。 RabbitMQ 在处理 HTTP 请求时是否适合做类似 RPC 的操作? 我有兴趣在收到用户 HTTP 请求时触发一条消息,等待来自后端服务器的响
在为我的网站编写 pingback 处理程序的过程中,我注意到 XML-RPC specification没有说明应该定义什么故障代码及其含义。所以问题是,是否有一个普遍接受的故障代码标准来指定这些信
我正在尝试创建一个可以演示 Telegram API 某些功能的小程序。我希望能够通过 SMS 注册和验证用户。根据user authorization guide ,我需要调用 auth.sendC
我将实现 JSON-RPC Web 服务。我需要这方面的规范。到目前为止,我只找到了一种可以称为真正规范的资源: JSON-RPC 1.0 http://json-rpc.org/wiki/speci
我需要学习Apache Thrift一个大学项目。这样tutorial说,它是一个 RPC 框架,也是我能找到的除 their documentation 之外的 Thrift 的唯一文档。 . 有人
我有一个多服务器多客户端应用程序,我想保留一些由单个守护进程管理的公共(public)数据(以避免并发的噩梦),这样服务器就可以在需要操作共享数据时询问它。 我已经在服务器中使用 libevent,所
我在我的代码中做了一个rpc。在成功方面,我有一些代码作为此 rpc 调用的触发器。 我的代码中有第二个 rpc。在另一个调用的成功端,我想执行第一个 rpc 成功端中的代码。 在不复制第一个rpc
我有一个奇怪的问题(希望您能提供帮助):我正在开发一个 GWT Web 应用程序,该应用程序有时会同时进行超过 4 - 5 个 GWT RPC 调用 - 就时间而言。 每隔一段时间 - 每 15 个电
我遇到了将大型 RPC 服务拆分成较小块的问题。我在这里找到了基础知识 GWT RPC - Multiple RPC Services Per App ,但我正在努力实现。我在任何地方都找不到任何好的
我目前正在使用具有一项大型 RPC 服务的 GWT 应用程序。它有 100 多个方法,所有方法都做不同的事情。如果将其拆分为多个 RPC 服务,我会获得什么样的性能优势/障碍?我相信我必须为每个人制作
有谁知道可以将 RPC/编码 WSDL 转换为 RPC/文字的工具或“黑盒”?我没有能力更改 API(这不是我的)但我想使用的工具不支持 RPC/Encoded。我想看看是否有人创建了一个简单的黑盒通
我正在调查使用 gorilla web toolkit创建一个简单的 RPC API。我正在使用他们文档中的示例,并且正在使用 Advanced Rest Client 进行测试在 Chrome 中使
由于 JSON-RPC 是面向过程的,因此我在 C# 中有一个 API 不会映射到 JSON-RPC。您将如何在 JSON-RPC 中表示面向对象的 API? 我当然可以使用 JSON-RPC 扩展,
我是来自意大利的计算机科学专业的学生,我必须做一个基于 的项目修改 Daemontools Of D.J. 的版本Bernstein 必须在 Unix 下实现远程过程调用。 通常,为了使用工具启动
我正在将 gwt 与 gwt-platform 结合使用,并使用调度异步进行服务器调用。我遇到的问题是我正在使用的操作没有被标记为可序列化或添加到 *.gwt.rpc 文件中。当我的代码运行时,我得到
我是一名优秀的程序员,十分优秀!