简体   繁体   English

Python 使用 Nameko 的微服务

[英]Python Microservices with Nameko

I'm trying to follow the simple Python Microservices with Nameko example.我正在尝试使用带有 Nameko 示例的简单 Python 微服务

I have both rabbitmq and rabbitmq management running in dockers:我在 docker 中运行了 rabbitmq 和 rabbitmq 管理:

docker run -d --hostname my-rabbit --name some-rabbit rabbitmq:3 docker 运行 -d --hostname my-rabbit --name some-rabbit rabbitmq:3

docker run -d --hostname my-rabbit --name mgmt-rabbit -p 15672:15672 rabbitmq:3-management docker run -d --hostname my-rabbit --name mgmt-rabbit -p 15672:15672 rabbitmq:3-management

I can browse to http://localhost:15672 and it's running.我可以浏览到 http://localhost:15672 并且它正在运行。

I have installed nameko by using:我已经使用以下方法安装了 nameko:

pip install nameko pip 安装名称ko

Created my virtualenv and created helloworld.py:创建了我的 virtualenv 并创建了 helloworld.py:

# helloworld.py

from nameko.rpc import rpc

class GreetingService:
    name = "greeting_service"

    @rpc
    def hello(self, name):
        return "Hello, {}!".format(name)

If I run any of these commands:如果我运行以下任何命令:

nameko run helloworld nameko 运行 helloworld

nameko run helloworld:GreetingService nameko 运行 helloworld:GreetingService

nameko run helloworld --broker amqp://guest:guest@localhost nameko 运行 helloworld --broker amqp://guest:guest@localhost

I get this error:我收到此错误:

Error: No module named 'helloworld'错误:没有名为“helloworld”的模块

What am I doing wrong?我究竟做错了什么?

When python looks for a module, it will look at __init__.py in your directory, you must check you have __init__.py file in your helloworld.py directory.当 python 查找模块时,它会在您的目录中查找__init__.py ,您必须检查您的 helloworld.py 目录中是否有__init__.py文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM