Created
June 26, 2020 12:10
-
-
Save velotiotech/3e6812a7277cc765dde2e4c77a707a67 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import grpc | |
from concurrent import futures | |
import time | |
import unary.unary_pb2_grpc as pb2_grpc | |
import unary.unary_pb2 as pb2 | |
class UnaryService(pb2_grpc.UnaryServicer): | |
def __init__(self, *args, **kwargs): | |
pass | |
def GetServerResponse(self, request, context): | |
# get the string from the incoming request | |
message = request.message | |
result = f'Hello I am up and running received "{message}" message from you' | |
result = {'message': result, 'received': True} | |
return pb2.MessageResponse(**result) | |
def serve(): | |
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) | |
pb2_grpc.add_UnaryServicer_to_server(UnaryService(), server) | |
server.add_insecure_port('[::]:50051') | |
server.start() | |
server.wait_for_termination() | |
if __name__ == '__main__': | |
serve() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment