async def async_setup(self): """Wait for the GRPC server to start""" self._grpc_server = grpc.aio.server(options=[ ('grpc.max_send_message_length', -1), ('grpc.max_receive_message_length', -1), ]) jina_pb2_grpc.add_JinaSingleDataRequestRPCServicer_to_server( self, self._grpc_server) jina_pb2_grpc.add_JinaDataRequestRPCServicer_to_server( self, self._grpc_server) jina_pb2_grpc.add_JinaControlRequestRPCServicer_to_server( self, self._grpc_server) jina_pb2_grpc.add_JinaDiscoverEndpointsRPCServicer_to_server( self, self._grpc_server) service_names = ( jina_pb2.DESCRIPTOR.services_by_name['JinaSingleDataRequestRPC']. full_name, jina_pb2.DESCRIPTOR.services_by_name['JinaDataRequestRPC']. full_name, jina_pb2.DESCRIPTOR.services_by_name['JinaControlRequestRPC']. full_name, jina_pb2.DESCRIPTOR.services_by_name['JinaDiscoverEndpointsRPC']. full_name, reflection.SERVICE_NAME, ) reflection.enable_server_reflection(service_names, self._grpc_server) bind_addr = f'0.0.0.0:{self.args.port}' self._grpc_server.add_insecure_port(bind_addr) self.logger.debug(f'start listening on {bind_addr}') await self._grpc_server.start()
async def async_setup(self): """ The async method to setup. Create the gRPC server and expose the port for communication. """ if not self.args.proxy and os.name != 'nt': os.unsetenv('http_proxy') os.unsetenv('https_proxy') self.server = grpc.aio.server(options=[ ('grpc.max_send_message_length', -1), ('grpc.max_receive_message_length', -1), ]) self._set_topology_graph() self._set_connection_pool() self.streamer = RequestStreamer( args=self.args, request_handler=handle_request( graph=self._topology_graph, connection_pool=self._connection_pool), result_handler=handle_result, ) self.streamer.Call = self.streamer.stream jina_pb2_grpc.add_JinaRPCServicer_to_server(self.streamer, self.server) jina_pb2_grpc.add_JinaControlRequestRPCServicer_to_server( self, self.server) bind_addr = f'{__default_host__}:{self.args.port_expose}' self.server.add_insecure_port(bind_addr) self.logger.debug(f' Start server bound to {bind_addr}') await self.server.start()
async def _async_setup_server(self): request_handler = RequestHandler(self.metrics_registry, self.name) self.streamer = RequestStreamer( args=self.args, request_handler=request_handler.handle_request( graph=self._topology_graph, connection_pool=self._connection_pool), result_handler=request_handler.handle_result(), ) self.streamer.Call = self.streamer.stream jina_pb2_grpc.add_JinaRPCServicer_to_server(self.streamer, self.server) jina_pb2_grpc.add_JinaControlRequestRPCServicer_to_server( self, self.server) service_names = ( jina_pb2.DESCRIPTOR.services_by_name['JinaRPC'].full_name, jina_pb2.DESCRIPTOR.services_by_name['JinaControlRequestRPC']. full_name, reflection.SERVICE_NAME, ) reflection.enable_server_reflection(service_names, self.server) bind_addr = f'{__default_host__}:{self.args.port}' if self.args.ssl_keyfile and self.args.ssl_certfile: with open(self.args.ssl_keyfile, 'rb') as f: private_key = f.read() with open(self.args.ssl_certfile, 'rb') as f: certificate_chain = f.read() server_credentials = grpc.ssl_server_credentials((( private_key, certificate_chain, ), )) self.server.add_secure_port(bind_addr, server_credentials) elif ( self.args.ssl_keyfile != self.args.ssl_certfile ): # if we have only ssl_keyfile and not ssl_certfile or vice versa raise ValueError( f"you can't pass a ssl_keyfile without a ssl_certfile and vice versa" ) else: self.server.add_insecure_port(bind_addr) self.logger.debug(f'start server bound to {bind_addr}') await self.server.start()
async def start_grpc_server(): grpc_server = grpc.aio.server( options=[ ('grpc.max_send_request_length', -1), ('grpc.max_receive_message_length', -1), ] ) jina_pb2_grpc.add_JinaControlRequestRPCServicer_to_server( DummyServer(), grpc_server ) grpc_server.add_insecure_port(f'localhost:{port}') await grpc_server.start() event.set() await grpc_server.wait_for_termination()
async def async_setup(self): """ Wait for the GRPC server to start """ self._grpc_server = grpc.aio.server(options=[ ('grpc.max_send_message_length', -1), ('grpc.max_receive_message_length', -1), ]) jina_pb2_grpc.add_JinaSingleDataRequestRPCServicer_to_server( self, self._grpc_server) jina_pb2_grpc.add_JinaDataRequestRPCServicer_to_server( self, self._grpc_server) jina_pb2_grpc.add_JinaControlRequestRPCServicer_to_server( self, self._grpc_server) bind_addr = f'0.0.0.0:{self.args.port_in}' self._grpc_server.add_insecure_port(bind_addr) self.logger.debug(f'Start listening on {bind_addr}') await self._grpc_server.start()
async def start_grpc_server(): grpc_server = grpc.aio.server(options=[ ('grpc.max_send_request_length', -1), ('grpc.max_receive_message_length', -1), ]) jina_pb2_grpc.add_JinaControlRequestRPCServicer_to_server( DummyServer(), grpc_server) service_names = ( jina_pb2.DESCRIPTOR.services_by_name['JinaControlRequestRPC']. full_name, reflection.SERVICE_NAME, ) reflection.enable_server_reflection(service_names, grpc_server) grpc_server.add_insecure_port(f'localhost:{port}') await grpc_server.start() event.set() await grpc_server.wait_for_termination()
async def _async_setup_grpc_server(self): """ Start the DataRequestHandler and wait for the GRPC server to start """ # Keep this initialization order # otherwise readiness check is not valid # The DataRequestHandler needs to be started BEFORE the grpc server self._data_request_handler = DataRequestHandler( self.args, self.logger, self.metrics_registry) self._grpc_server = grpc.aio.server(options=[ ('grpc.max_send_message_length', -1), ('grpc.max_receive_message_length', -1), ]) jina_pb2_grpc.add_JinaSingleDataRequestRPCServicer_to_server( self, self._grpc_server) jina_pb2_grpc.add_JinaDataRequestRPCServicer_to_server( self, self._grpc_server) jina_pb2_grpc.add_JinaControlRequestRPCServicer_to_server( self, self._grpc_server) jina_pb2_grpc.add_JinaDiscoverEndpointsRPCServicer_to_server( self, self._grpc_server) service_names = ( jina_pb2.DESCRIPTOR.services_by_name['JinaSingleDataRequestRPC']. full_name, jina_pb2.DESCRIPTOR.services_by_name['JinaDataRequestRPC']. full_name, jina_pb2.DESCRIPTOR.services_by_name['JinaControlRequestRPC']. full_name, jina_pb2.DESCRIPTOR.services_by_name['JinaDiscoverEndpointsRPC']. full_name, reflection.SERVICE_NAME, ) reflection.enable_server_reflection(service_names, self._grpc_server) bind_addr = f'0.0.0.0:{self.args.port}' self.logger.debug(f'start listening on {bind_addr}') self._grpc_server.add_insecure_port(bind_addr) await self._grpc_server.start()