Node example
This commit is contained in:
@ -1,8 +1,13 @@
|
||||
import logging
|
||||
import grpc
|
||||
from models import GetCurrentTimeResponse
|
||||
from stubs import serve_hours_pb2
|
||||
from stubs import serve_hours_pb2_grpc
|
||||
from stubs import serve_currenttime_pb2
|
||||
from stubs import serve_currenttime_pb2_grpc
|
||||
|
||||
SERVE_CURRENTTIME_HOST = "localhost"
|
||||
SERVE_CURRENTTIME_PORT = 50000
|
||||
SERVE_HOURS_HOST = "localhost"
|
||||
SERVE_HOURS_PORT = 50001
|
||||
SERVE_MINUTES_HOST = "localhost"
|
||||
@ -23,10 +28,24 @@ def get_hours() -> int:
|
||||
return response.hours
|
||||
|
||||
|
||||
def get_currenttime() -> GetCurrentTimeResponse:
|
||||
with grpc.insecure_channel(
|
||||
f"{SERVE_CURRENTTIME_HOST}:{SERVE_CURRENTTIME_PORT}"
|
||||
) as channel:
|
||||
stub = serve_currenttime_pb2_grpc.ServeCurrentTimeServiceStub(channel)
|
||||
raw_response = stub.GetCurrentTime(
|
||||
serve_currenttime_pb2.GetCurrentTimeRequest(timezone=TIMEZONE)
|
||||
)
|
||||
return GetCurrentTimeResponse.from_orm(raw_response)
|
||||
|
||||
|
||||
def run():
|
||||
hours = get_hours()
|
||||
print(">>>>>>>>>>>>> Hours:", hours)
|
||||
|
||||
currenttime = get_currenttime()
|
||||
print(">>>>>>>>>>>>> CurrentTime:", currenttime)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
logging.basicConfig()
|
||||
|
||||
Reference in New Issue
Block a user