Пример #1
0
def server_bidirectional_stream_call_one_by_one():
    """
    双向流模式,客户端处理,一个请求对应一个响应的情况
    通过队列传递交互传递参数
    """
    # 清空队列
    TEMP_QUEUE.queue.clear()

    # 处理
    _connect_para = SimpleGRpcTools.generate_connect_para(ip='127.0.0.1',
                                                          port=50051)
    with SimpleGRpcTools.generate_channel(_connect_para) as channel:
        # # 注意队列一定要先传入一个值
        TEMP_QUEUE.put(None)
        _cresult_iterator = SimpleGRpcTools.grpc_call_by_channel(
            channel,
            bidirectional_stream_one_by_one_generator(),
            call_mode=EnumCallMode.BidirectionalStream)
        for _cresult in _cresult_iterator:
            # 放入队列
            s = _cresult.return_json
            TEMP_QUEUE.put(s)
            if not _cresult.is_success():
                return False
    return True
Пример #2
0
def server_bidirectional_stream_call_n_by_one():
    """
    双向流模式,客户端处理,多个请求对应一个响应的情况
    """
    # 处理
    _connect_para = SimpleGRpcTools.generate_connect_para(ip='127.0.0.1',
                                                          port=50051)
    with SimpleGRpcTools.generate_channel(_connect_para) as channel:
        _cresult_iterator = SimpleGRpcTools.grpc_call_by_channel(
            channel,
            bidirectional_stream_n_by_one_generator(),
            call_mode=EnumCallMode.BidirectionalStream)
        for _cresult in _cresult_iterator:
            # 打印
            print('bidirectional_stream_n_by_one client get: ' +
                  _cresult.return_json)
            if not _cresult.is_success():
                return False
    return True
Пример #3
0
def server_side_stream_call(a, b, *args, **kwargs):
    """
    服务端流模式,真正调用服务端的函数
    """
    # 转换参数
    _para_values = RunTool.get_current_function_parameter_values(
        is_simple_mode=True)
    _para_obj = SimpleGRpcTools.parameters_to_json(_para_values)
    _req_obj = SimpleGRpcTools.generate_request_obj(
        service_name='service_server_side_stream',
        para_json=_para_obj.para_json,
        has_para_bytes=_para_obj.has_para_bytes,
        para_bytes=_para_obj.para_bytes)
    _connect_para = SimpleGRpcTools.generate_connect_para(ip='127.0.0.1',
                                                          port=50051)
    with SimpleGRpcTools.generate_channel(_connect_para) as channel:
        _cresult_iterator = SimpleGRpcTools.grpc_call_by_channel(
            channel, _req_obj, call_mode=EnumCallMode.ServerSideStream)
        for _cresult in _cresult_iterator:
            if not _cresult.is_success():
                return False
    return True