def _init_rpc(self) -> FlaskPooledClusterRpcProxy: """Initialize the RPC proxy. Returns: The instantiated FlaskPooledClusterRpcProxy object """ self._service.config.update({ "NAMEKO_AMQP_URI": f"pyamqp://{settings.RABBIT_USER}:{settings.RABBIT_PASSWORD}" f"@{settings.RABBIT_HOST}:{settings.RABBIT_PORT}" }) rpc = FlaskPooledClusterRpcProxy() rpc.init_app(self._service) return rpc
def _init_rpc(self) -> FlaskPooledClusterRpcProxy: """Initalizes the RPC proxy Returns: FlaskPooledClusterRpcProxy -- The instantiated FlaskPooledClusterRpcProxy object """ self._service.config.update({ "NAMEKO_AMQP_URI": "pyamqp://{0}:{1}@{2}:{3}".format(environ.get("RABBIT_USER"), environ.get("RABBIT_PASSWORD"), environ.get("RABBIT_HOST"), environ.get("RABBIT_PORT")) }) rpc = FlaskPooledClusterRpcProxy() rpc.init_app(self._service) return rpc
from flask import Flask from flask_cors import CORS from flask_nameko import FlaskPooledClusterRpcProxy from dotenv import load_dotenv import os BASEDIR = os.path.dirname(os.path.abspath(__file__)) load_dotenv(dotenv_path="{}/.env".format(BASEDIR)) app = Flask(__name__) CORS(app) CONFIG_METHOD = "main.config.{}".format( os.environ.get("APP_SETTINGS", "Develop")) app.config.from_object(CONFIG_METHOD) rpc = FlaskPooledClusterRpcProxy() rpc.init_app(app)
monkey.patch_all() # 用于协程异步感知IO操作,打的补丁 def create_app(): flask_app = Flask(__name__) flask_app.config['JSON_SORT_KEYS'] = False flask_app.config['JSON_AS_ASCII'] = False flask_app.config.update( dict(NAMEKO_AMQP_URI="pyamqp://*****:*****@localhost")) return flask_app app = create_app() Swagger(app) # 用于API注释可视化 rpc = FlaskPooledClusterRpcProxy() rpc.init_app(app) # 一次注册,绑定使用 @app.route('/', methods=['GET']) def get_apis(): return json.dumps({"web_state": "success"}), 200 @app.route('/hello_world', methods=['GET']) def hello(): """ Micro Service for hello, say hello to you. 中文说明:这是一个say hello的接口。 --- parameters: - in: query