No route between Nameko and Flask

934 views Asked by At

if you saw my last question one hour ago or almost) !

I managed to resolve a lot of problems but I'm stuck with one and I can't understand why I have it. I prefer to make a new thread because the error isn't the same and for future readers, it will be clearer.

My goal, as I said in the last question, is to have microservices with Python and Nameko, sending results and receiving informations and queries from a Flask webapp (and in the future, from many Flask web app). But I now have a - 312 - route problem.

Code from my Nameko app :

# -*-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

Code from 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)

And now, the error :

 * 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

I'll stay on this thread now to finish my tests (if I have another problem I can't solve). After that, I think I will be able to make my framework thanks to that. Any advice, hints or help for this one, for the moment ?

Thank you in advance.

2

There are 2 answers

5
Matt On BEST ANSWER

The name attribute on the service class is how you address the service.

class firstService:
    name = "first"

    @rpc
    def method(self):
        pass

So

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

Also it looks like you're using a too-modern version of py-amqp. Did you upgrade it since installing Nameko? It should be v1.4.9. With that version you get a more helpful "Unknown Service" error returned.

6
Druta Ruslan On

RabbitMQ sends back with 'basic.return' when a 'mandatory' message cannot be delivered to any queue.

Can you run this ?

rabbitmq-plugins enable rabbitmq_management

and then open

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

logged in with acc guest and password guest docs

and there will be all information about queues channels exchanges etc.

is there the queue declared where you want to send the message ?

if there is not queue create it