Created
April 11, 2024 13:31
-
-
Save rakia/3acdd26c138da0b1dc223b6acb4204f6 to your computer and use it in GitHub Desktop.
Server-side logic of GetWeather ProtoBuf (gRPC) service
This file contains hidden or 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
from concurrent import futures | |
import grpc | |
import weather_pb2 | |
import weather_pb2_grpc | |
class WeatherServicer(weather_pb2_grpc.WeatherServiceServicer): | |
def GetWeather(self, request, context): | |
# Implement the logic to retrieve the weather here. For simplicity, returning a fixed value. | |
return weather_pb2.GetWeatherResponse(temperature=22.5) | |
def serve(): | |
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) | |
weather_pb2_grpc.add_WeatherServiceServicer_to_server(WeatherServicer(), 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