Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gRPC streaming with envoy wasm #1

Closed
NomadXD opened this issue Mar 21, 2021 · 4 comments
Closed

gRPC streaming with envoy wasm #1

NomadXD opened this issue Mar 21, 2021 · 4 comments

Comments

@NomadXD
Copy link

NomadXD commented Mar 21, 2021

Thanks a lot for the example of envoy wasm filter with gRPC unary request. Have you tried it with gRPC streaming ? In the proto file, you have defined a server streaming service but couldn't find any implementation. I'm trying to use gRPC bidi streaming. I have a native C++ filter that I want to re-implement as WASM.

@NomadXD
Copy link
Author

NomadXD commented Mar 22, 2021

what's so confusing is
auto res = root()->grpcStreamHandler(grpc_service_string, EchoServerServiceName, PublishMetadataMethodName, initial_metadata,std::unique_ptr<GrpcStreamHandlerBase>(new MyGrpcCallStreamHandler(this)));
returns a WasmResult. So if we are using a grpc streaming from a filter we have to ,

MyGrpcCallStreamHandler streamHandler_ = new MyGrpcCallStreamHandler(this);
auto res = root()->grpcStreamHandler(grpc_service_string, EchoServerServiceName,EchoMethodName, initial_metadata,std::unique_ptr<GrpcStreamHandlerBase>(streamHandler_));

from onCreate in context.

and then implement some methods in MyGrpcCallStreamHandler to make it possible for the ExampleFilter to call the send method in MyGrpcCallStreamHandler. Is that the correct way to do it ?

@NomadXD
Copy link
Author

NomadXD commented Mar 22, 2021

I would be so thankful if you can provide a sample code snippet since there's no any other examples related to this and I'm blocked here for couple of days.

@salrashid123
Copy link
Owner

i really don't know cpp that well at all to construct a sample but you would use grpcStreamHandler() as the way to get this done.

what i'm not sure which mode you need (server,client or bidi) but that function should be the thing to use.

i know go better so i'm going to update this snippet once proy-wasm-go-sdk#14 is addressed

@NomadXD
Copy link
Author

NomadXD commented Mar 22, 2021

For me the issue is not with using grpcStreamHandler(). See these 2 method definitions for example.

WasmResult grpcCallHandler(std::string_view service, std::string_view service_name,
                             std::string_view method_name,
                             const HeaderStringPairs &initial_metadata, std::string_view request,
                             uint32_t timeout_milliseconds,
                             std::unique_ptr<GrpcCallHandlerBase> handler);

And for the streamHandler()

WasmResult grpcStreamHandler(std::string_view service, std::string_view service_name,
                               std::string_view method_name,
                               const HeaderStringPairs &initial_metadata,
                               std::unique_ptr<GrpcStreamHandlerBase> handler);

For unary calls, that method directly sends the request. But for streams that method just create a stream and we have to implement another class by inheriting from GrpcStreamHandler and use their send() method to send a request.

class MyGrpcCallStreamHandler : public GrpcStreamHandler<google::protobuf::Value, google::protobuf::Value>

What I don't understand is how to call that method from the filter class. For the native filter I pass a reference to StreamHandler in the constructor of the filter. Here I'm not sure where to pass that. Maybe from on the onCreate() method of the filter. Thanks for the response.

@NomadXD NomadXD closed this as completed Sep 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants