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

wasm extension with gRPC bidi streams #58

Open
NomadXD opened this issue Mar 22, 2021 · 4 comments
Open

wasm extension with gRPC bidi streams #58

NomadXD opened this issue Mar 22, 2021 · 4 comments

Comments

@NomadXD
Copy link

NomadXD commented Mar 22, 2021

Is there any example of a wasm extension that uses gRPC bidi streaming ? For gRPC unary, there are some examples. But for gRPC bidi streams couldn't find any examples. I would really appreciate if someone can provide a sample code snippet of using grpc bidi streams from a filter since there are no resources currently available for that. Thanks

@bianpengyuan
Copy link
Collaborator

No we don't have one yet. We can add that.

@NomadXD
Copy link
Author

NomadXD commented Mar 22, 2021

@bianpengyuan yeah that would be great to have. I have a native C++ filter and I'm trying to re-implement it in WASM , so I don't have to build it everytime with bazel. I have some question regarding the grpc streaming APIs in proxy_wasm_api.h. Can I ask it here if you won't mind ?

@bianpengyuan
Copy link
Collaborator

I've never tried the gRPC stream API, so not sure how much I can help.

Meanwhile, I don't think bazel is quite avoidable when you write Wasm module with C++. Especially when you use protobuf / gRPC. Although Bazel based build for C++ Wasm extension is way easier than native Envoy filter.

@NomadXD
Copy link
Author

NomadXD commented Mar 22, 2021

@bianpengyuan yeah that's true. I just want to avoid the native envoy build. I actually want to have both native and WASM filters, so it's more flexible to have options. I'll just describe my question below, if you are familiar with it you can answer. So my filter needs to use the gRPC bidi streams to communicate with an external service. I want to create a stream per every filter object and use the stream to send data to the external service.

The WASM api has this following method will creates a stream and delegates the stream management to the GrpcStreamHanlder class.

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);

So we have to implement that class like ExampleGrpcStreamHanlder: public GrpcStreamHanlder<Request,Response> and implement relevant methods like onResponse(), onRemoteClose(). And if I want to send a message to the external service, I have to call the send() method in GrpcStreamHanlder. To call it from my filter I need to have some reference to GrpcStreamHanlder. In the C++ native filter, I pass the grpc client to the filter constructor. Here I'm not sure where I should pass that reference. Sorry if what i'm saying is not clear to you.

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