def create_async_channel_stub( address, https=False, root_certificates: Optional[str] = None, ) -> Tuple[jina_pb2_grpc.JinaSingleDataRequestRPCStub, jina_pb2_grpc.JinaDataRequestRPCStub, jina_pb2_grpc.JinaControlRequestRPCStub, grpc.aio.Channel, ]: """ Creates an async GRPC Channel. This channel has to be closed eventually! :param address: the address to create the connection to, like 127.0.0.0.1:8080 :param https: if True, use https for the grpc channel :param root_certificates: the path to the root certificates for https, only u :returns: DataRequest/ControlRequest stubs and an async grpc channel """ channel = GrpcConnectionPool.get_grpc_channel( address, asyncio=True, https=https, root_certificates=root_certificates, ) return ( jina_pb2_grpc.JinaSingleDataRequestRPCStub(channel), jina_pb2_grpc.JinaDataRequestRPCStub(channel), jina_pb2_grpc.JinaControlRequestRPCStub(channel), channel, )
def _create_connection(self, target): self._logger.debug(f'create connection to {target}') channel = grpc.aio.insecure_channel( target, options=[ ('grpc.max_send_message_length', -1), ('grpc.max_receive_message_length', -1), ], ) return jina_pb2_grpc.JinaDataRequestRPCStub(channel)
def _create_grpc_stub(pod_address, is_async=True): if is_async: channel = grpc.aio.insecure_channel( pod_address, options=[ ('grpc.max_send_message_length', -1), ('grpc.max_receive_message_length', -1), ], ) else: channel = grpc.insecure_channel( pod_address, options=[ ('grpc.max_send_message_length', -1), ('grpc.max_receive_message_length', -1), ], ) stub = jina_pb2_grpc.JinaDataRequestRPCStub(channel) return stub
def send_requests_sync( requests: List[Request], target: str, timeout=100.0, tls=False, root_certificates: Optional[str] = None, endpoint: Optional[str] = None, ) -> Request: """ Sends a list of requests synchronically to the target via grpc :param requests: the requests to send :param target: where to send the request to, like 127.0.0.1:8080 :param timeout: timeout for the send :param tls: if True, use tls for the grpc channel :param root_certificates: the path to the root certificates for tls, only used if tls is True :param endpoint: endpoint to target with the request :returns: the response request """ for i in range(3): try: with GrpcConnectionPool.get_grpc_channel( target, tls=tls, root_certificates=root_certificates, ) as channel: metadata = (('endpoint', endpoint), ) if endpoint else None stub = jina_pb2_grpc.JinaDataRequestRPCStub(channel) response, call = stub.process_data.with_call( requests, timeout=timeout, metadata=metadata, ) return response except grpc.RpcError as e: if e.code() != grpc.StatusCode.UNAVAILABLE or i == 2: raise