thejinchao / turbolink

TurboLink is an unreal engine plugin enables Google gRPC work with Unreal Engine using C++ and Blueprint
MIT License
129 stars 32 forks source link

[Question] Deadline and metadata support #30

Closed savasozer closed 2 months ago

savasozer commented 7 months ago

Hi, First of all, thank you for bringing such a plugin to Unreal's weak ecosystem :) Am I missing something or are gRPC deadline and metadata not supported yet? If they aren't supported, can you give me a hint on how to add them?

thejinchao commented 6 months ago

Indeed, I have not considered these two features because I have not used them in actual projects, so I have not put them in. However, I remember that they are all related to ClientContext, so I suggest that you put them in the initialization of the RPC interface, such as the following code

FGrpcContextHandle UGreeterServiceClient::InitHello()
{
    FGrpcContextHandle handle = Service->TurboLinkManager->GetNextContextHandle();
    auto context = UGrpcClient::MakeContext<GrpcContext_GreeterService_Hello>(handle);
    context->RpcContext = UTurboLinkGrpcManager::Private::CreateRpcClientContext();
    //meta data
    context->RpcContext->AddMetadata("key1", "value1");
    //dead line
    std::chrono::time_point deadline = std::chrono::system_clock::now() +
        std::chrono::milliseconds(100);
    context->RpcContext->set_deadline(deadline);

    return context->GetHandle();
}
UnrealCraic commented 5 months ago

Further to the above this would be an addition to presumably auto generated code from protoc-gen-turbolink which is subject to being removed next time the code is regenerated.

I had the same issue and due to the AddMetadata function being defined in a class private to the plugin I went with the approach of AddMetadataToContext(Handle, Key, Value) to the ugrpcclient class which can be called from outside of the plugin (I have an unreal module which depends on the plugin but handles grpc stuff without other game modules having a dependency on any of the included libraries). The function simply finds the grpccontext in the context map using the supplied handle and calls the AddMetaData on the found context's RpcContext. Let me know if this is a potentially problematic solution but so far so good for me

Edit: btw this plugin is fantastic, thanks for the great work!

thejinchao commented 2 months ago

The metadata and deadline feature is already supported in version v1.4.1