-
-
Save fzankl/66bd56bbfbf0a7abd5da6afb581a65a0 to your computer and use it in GitHub Desktop.
Sample how create a gRPC server using Python and Unix Domain Sockets
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 foo_pb2_grpc | |
import foo_pb2 | |
class Foo(foo_pb2_grpc.FooServicer): | |
def GetFoo(self, request, context): | |
return foo_pb2.FooResponse(message='Python based gRPC server receives over Unix Domain Socket: ' + request.message) | |
def serve(): | |
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) | |
foo_pb2_grpc.add_FooServicer_to_server(Foo(), server) | |
server.add_insecure_port('unix:///tmp/foo.sock') | |
server.start() | |
print('gRPC server started using Unix Domain Socket') | |
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