• python利用第三方模块nameko使用rpc模块实现微服务


    客户端
    # !/usr/bin/env python3
    # -*- coding: utf-8 -*-
    from nameko.standalone.rpc import ClusterRpcProxy
    CONFIG = {'AMQP_URI': "amqp://mq用户名:mq密码@ip地址"}
    def xx_rpc(name):
    try:
    with ClusterRpcProxy(CONFIG) as rpc:
    data = rpc.agent_device_log_service.hello1(name)
    except Exception as e:
    return False
    return data

    服务端
    # !/usr/bin/env python3
    # -*- coding: utf-8 -*-
    from nameko.rpc import rpc

    class DeviceService:
        name = "agent_device_log_service    @rpc    def hello1(self,name):
            return "hello world{name}"

    @rpc
    def hello2(self):
    return "hello world2"


    配置文件
    config.yaml
    AMQP_URI: 'pyamqp://账号:密码@ip地址'
    WEB_SERVER_ADDRESS: '0.0.0.0:9000'
    rpc_exchange: 'nameko-rpc'
    max_workers: 10
    parent_calls_tracked: 10

    LOGGING:
    version: 1
    handlers:
    console:
    class: logging.StreamHandler
    root:
    level: DEBUG
    handlers: [console]
    使用nameko必须使用rabbitmq 没有下载可以参考 ---》 https://www.cnblogs.com/yz-w/p/15132156.html

    需要在文件__init__导入DeviceService 例: from src.entry import DeviceService
    切换src上级目录至entry命令行:nameko run --config config.yaml src:DeviceService



     
     
  • 相关阅读:
    07 selenium模块基本使用
    06 高性能异步爬虫
    05 request高级操作
    04 验证码识别
    03 数据解析
    02 requests模块
    01 爬虫简介
    Get和Post的正解
    pytoch之 encoder,decoder
    pytorch之 RNN 参数解释
  • 原文地址:https://www.cnblogs.com/yz-w/p/15132419.html
Copyright © 2020-2023  润新知