如果你在一小时前或几乎看到我的最后一个问题)!
我设法解决了很多问题,但是我坚持了一个,我无法理解为什么会这样。我更喜欢创建一个新主题,因为错误并不相同,对于未来的读者来说,它会更清晰。
正如我在上一个问题中所说,我的目标是使用Python和Nameko提供微服务,从Flask webapp(以及将来许多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 app的代码:
#! /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
我现在留在这个线程上完成我的测试(如果我还有其他问题我无法解决)。在那之后,我想我能够通过它来制作我的框架。目前有任何建议,提示或帮助吗?
提前谢谢。
答案 0 :(得分:1)
RabbitMQ发送回&#39; basic.return&#39;当一个强制性的&#39;消息无法传递到任何队列。
你能跑这个吗?rabbitmq-plugins enable rabbitmq_management
然后打开
http://server-name:15672/ #server-name i think is `localhost`
使用acc guest
和密码guest
docs
并且会有关于queues
channels
exchanges
等的所有信息。
是否已声明queue
您要发送消息的位置?
如果没有queue
创建
答案 1 :(得分:1)
服务类的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。使用该版本,您将收到更有用的“未知服务”错误。