Ryu
  • 👩🏻‍💻 Ryu / software_engineer
  • ✨Resume
  • Python3
    • Python3 가상환경 설정하기
      • Python3 vs Python2
      • Pyenv
      • Venv
      • Pip
    • Flask
      • Flask 설치하기
      • API Server 만들기
    • REST API
    • Command Line 활용하기
    • Module 사용하기
      • Pickle - 자료형을 파일로 저장할 때
    • MongoDB connection
      • Pymongo
    • WSGI
      • 💡WSGI 가 필요한 이유
      • Web Server / WSGI / Middleware / Application 구조
      • WSGI Middleware 종류
      • Gunicorn
        • Gunicorn vs Uwsgi
    • Dockerize
      • 💡Dockerize 가 필요한 이유
      • 1. Create Dockerfile
        • Gunicorn 으로 nginx 와 app 연결하기
    • Kubernetes 로 배포하기
      • 💡Kubernetes 가 필요한 이유
      • Helm 사용하기
      • Helm 으로 k8s 에 앱 배포하기
  • Open Tracing (정리중)
    • Open Tracing 이란 무엇인가
    • Python OpenTracing Example
    • Jaeger, Jaeger UI
    • Python Jaeger Tutorial
    • Zipkin 알아보기
    • Jaeger-client 리스팅
  • Microservice Architecture
    • Netflix의 MSA 컨셉
      • ⚡️ MSA 를 도입할때 고려해야할 점들
  • Paper
    • Dynamo: Amazon’s Highly Available Key-value Store
      • 1. Introduction
      • 2. Background
      • 3. Related Work
        • Related Paper) Pastry, Chord
        • Byzantine Fault Tolerance
      • 4. System Architecture
        • 4.1 System Interface
        • 4.2 Partitioning
        • 4.3 Replication
        • Hash Function
  • Frontend
    • CommonJS 와 AMD
    • RequireJS
    • WebSocket
      • WebSocket vs Socket.io
      • polling vs long polling vs streaming
    • Vue.js
      • Vue.js 에서 WebSocket 사용하기
      • [프로젝트] Vue, Vuex, AntDesignVue 로 운영툴 만들기
    • React x Redux 로 프로젝트 만들기
      • 0. React, Redux 를 선택한 이유
      • 1. 프로젝트 생성하고 Webpack4 적용하기
      • 2. React 와 ReactDOM 적용하기
      • 3. Material UI 적용하기
  • Data Engineering
    • Spark
      • Spark 이란?
      • 각 데몬의 역할 Driver, Master, Worker
      • 장단점 / 함께사용하는 툴 / 사용 사례
  • Service Mesh (정리중)
    • RPC
    • gRPC - Python Server 만들기
      • step 2.
Powered by GitBook
On this page
  • 🔗 Link
  • Step
  • Pre
  • Installation
  • Clone Example App
  • Run a gRPC App
  • Demo code
  • Generate gRPC code

Was this helpful?

  1. Service Mesh (정리중)

gRPC - Python Server 만들기

PreviousRPCNextstep 2.

Last updated 5 years ago

Was this helpful?

🔗 Link

  • gRPC 공식 문서 (python):

  • gRPCio Github:

  • gRPCio pypi:

Step

1) pf 정보 가져오는 서비스를 python grpc 서버로 wrapping (이때 proto buf 정의)

Pre

$ pyenv versions
$ pyenv 3.7.0
$ source env/bin/activate
$ pip install --upgrade pip

Installation

$ python -m pip install grpcio
$ pip install grpcio-tools

Clone Example App

$ git clone -b v1.22.0 https://github.com/grpc/grpc
$ cd grpc/examples/python/helloworld

Run a gRPC App

$ python greeter_server.py

## 다른 탭에서
$ python greeter_client.py

Demo code

// pfservice.proto

syntax = "proto3";

option java_multiple_files = true;
option java_package = "io.grpc.examples.helloworld";
option java_outer_classname = "HelloWorldProto";
option objc_class_prefix = "HLW";



// helloworld.poroto 복사해왔고
packagep lusfriend.service;


//
service PlusfriendService {
  // Sends a greeting
  rpc GetProfiles (ReqProfiles) returns (ResProfiles) {}
}


message Profile {
    uint32 id = 1;
    uint32 friend_count = 2;
}

// 프로필 조회하는 request 라서, id 리스트를 받을것이므로 Profile 메세지를 새로만들고 그것을 여러개 보내기로.
message ReqProfiles {
  repeated string ids = 1;
}

// The response message containing the greetings
message ResProfiles {
  repeated Profile profiles = 1;
}

Generate gRPC code

$ python -m grpc_tools.protoc -I../../protos --python_out=. --grpc_python_out=. ../../protos/helloworld.proto
  • grpc client 가 있어서 curl 처럼 테스트해볼 수 있음. (-> 에디 참고)

    • zshrc 에 #grpc_tools ? 머 그런거 있음/

  • reflection 무엇

----

gRPC 의 http request 클라이언트 찾아보기

  • aiohttp 등을 사용해야하지만,

  • 일단은 블록킹 되더라도 일반 리퀘스트로 만들어보자.

$ pip install requests

/server.py

ids = ','.join(request.ids)
https://grpc.io/docs/quickstart/python/
https://github.com/grpc/grpc/tree/master/src/python/grpcio
https://pypi.org/project/grpcio/