-
Notifications
You must be signed in to change notification settings - Fork 0
/
public_server.py
36 lines (28 loc) · 1.09 KB
/
public_server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import logging
import asyncio
import grpc
from definitions_pb2 import HiddenRequest, PublicResponse
from definitions_pb2_grpc import (
PublicServiceServicer,
add_PublicServiceServicer_to_server,
HiddenServiceStub,
)
class PublicService(PublicServiceServicer):
async def DoPublicRequest(self, request, context):
logging.info("Sending request to hidden.")
async with grpc.aio.insecure_channel("localhost:50052") as channel:
stub = HiddenServiceStub(channel)
request = HiddenRequest(message="The client sends their regards.")
response = await stub.DoHiddenRequest(request)
logging.info(response)
return PublicResponse(message="Hello from public.")
async def serve():
server = grpc.aio.server()
add_PublicServiceServicer_to_server(PublicService(), server)
server.add_insecure_port("[::]:50051")
logging.info("Starting public service.")
await server.start()
await server.wait_for_termination()
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
asyncio.run(serve(), debug=False)