Nameko 和 Flask 之间没有路由

No route between Nameko and Flask

如果你在一小时前或几乎一小时前看到我的最后一个问题)!

我设法解决了很多问题,但我被一个问题困住了,我不明白为什么我会遇到它。我更喜欢创建一个新线程,因为错误不一样,对于未来的读者来说,它会更清楚。

正如我在上一个问题中所说,我的目标是使用 Python 和 Nameko 提供微服务,从 Flask web 应用程序(以及将来,从许多 Flask web 应用程序)发送结果并接收信息和查询应用程序)。但是我现在有一个 - 312 - 路由问题。

来自我的 Nameko 应用程序的代码:

# -*-coding:utf-8 -*

# namekotesting.py

from nameko.rpc import rpc

class firstService:
        name = "First microservice"
        result = "";

        @rpc
        def mymethode(self, test):
                result = test
                return result

来自 Flask 应用程序的代码:

#! /usr/bin/python
# -*- coding:utf-8 -*-

from flask import Flask, request
from flasgger import Swagger
from nameko.standalone.rpc import ClusterRpcProxy

app = Flask(__name__)
Swagger(app)
CONFIG = {'AMQP_URI': "amqp://guest:guest@<myipserverhere>:5672"}

@app.route('/', methods=['GET', 'POST'])

def mymethode():
        with ClusterRpcProxy(CONFIG) as rpc:
                littletest = rpc.firstService.mymethode("hello")

def index():
        return littletest

if __name__ == '__main__':
    app.run(host='0.0.0.0', debug=True, port=5000)

现在,错误:

 * Serving Flask app "flasktest" (lazy loading)
 * Environment: production
   WARNING: Do not use the development server in a production environment.
   Use a production WSGI server instead.
 * Debug mode: on
 * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 126-185-375
[03/Jun/2018 21:04:27] "GET / HTTP/1.1" 500 -
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 2309, in __call__
    return self.wsgi_app(environ, start_response)
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 2295, in wsgi_app
    response = self.handle_exception(e)
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1741, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 2292, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1815, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1718, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1813, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1799, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/oyo/flasktest/flasktest.py", line 16, in mamethode
    petittest = rpc.premierService.mamethode("voici")
  File "/usr/local/lib/python2.7/dist-packages/nameko/rpc.py", line 368, in __call__
    reply = self._call(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/nameko/rpc.py", line 437, in _call
    extra_headers=extra_headers
  File "/usr/local/lib/python2.7/dist-packages/nameko/amqp/publish.py", line 189, in publish
    **publish_kwargs
  File "/usr/local/lib/python2.7/dist-packages/kombu/messaging.py", line 181, in publish
    exchange_name, declare,
  File "/usr/local/lib/python2.7/dist-packages/kombu/connection.py", line 494, in _ensured
    return fun(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/kombu/messaging.py", line 203, in _publish
    mandatory=mandatory, immediate=immediate,
  File "/usr/local/lib/python2.7/dist-packages/amqp/channel.py", line 1743, in basic_publish_confirm
    self.wait(spec.Basic.Ack)
  File "/usr/local/lib/python2.7/dist-packages/amqp/abstract_channel.py", line 79, in wait
    self.connection.drain_events(timeout=timeout)
  File "/usr/local/lib/python2.7/dist-packages/amqp/connection.py", line 491, in drain_events
    while not self.blocking_read(timeout):
  File "/usr/local/lib/python2.7/dist-packages/amqp/connection.py", line 497, in blocking_read
    return self.on_inbound_frame(frame)
  File "/usr/local/lib/python2.7/dist-packages/amqp/method_framing.py", line 77, in on_frame
    callback(channel, msg.frame_method, msg.frame_args, msg)
  File "/usr/local/lib/python2.7/dist-packages/amqp/connection.py", line 501, in on_inbound_method
    method_sig, payload, content,
  File "/usr/local/lib/python2.7/dist-packages/amqp/abstract_channel.py", line 128, in dispatch_method
    listener(*args)
  File "/usr/local/lib/python2.7/dist-packages/amqp/channel.py", line 1960, in _on_basic_return
    raise exc
ChannelError: Basic.return: (312) NO_ROUTE

我现在将留在这个线程上以完成我的测试(如果我有其他我无法解决的问题)。在那之后,我想我将能够通过它来制作我的框架。目前对此有任何建议、提示或帮助吗?

提前致谢。

当无法将 'mandatory' 消息传送到任何队列时,RabbitMQ 会返回 'basic.return'。

你能运行这个吗?

rabbitmq-plugins enable rabbitmq_management

然后打开

http://server-name:15672/ #server-name i think is `localhost` 

使用帐号 guest 和密码 guest 登录 docs

还有queueschannelsexchanges等所有信息

是否有 queue 声明要发送消息的位置?

如果没有queue创建它

服务 class 上的 name 属性是您处理服务的方式。

class firstService:
    name = "first"

    @rpc
    def method(self):
        pass

所以

>>> rpc.firstService.method()  # won't work
>>> rpc.first.method()         # will work

另外,您似乎使用的是太现代的 py-amqp 版本。安装 Nameko 后你升级了吗?它应该是 v1.4.9。使用该版本,您会返回更有用的 "Unknown Service" 错误。