gRPC Streaming with Tyk native golang plugin

Hello Everyone.

I have come across a very interesting use case, where we have streaming servers running on custom protocol on backend and those are exposed to clients on front end over gRPC protocol.

End User (gRPC/Proto) ->>>> (Tyk GW) – (Tyk Middleware Plugin) ----> Streaming backend (Custom proto)

The way, I have implemented is by developing golang plugin handling the Custom proto streaming to gRPC streaming.

I have used, golang grpc.ServeHTTP() methods, where we are using existing http request /response handlers, serving over gRPC.

The issue I am facing is, this mechanism works perfect for gRPC unary ops. However, for streaming ops, I am facing issue with tyk is not flushing the streams before actuall accumulated data is NOT more than 4096 bytes. I need the stream data be flushed out immediately.

I tried several options on
1. Setting up http/ grpc WriteByfferSize to the minimal values.
2. Flusher methods are NOT implemented on the wrapper, so could not use it

Any help by any means is appreciated.

Hi @Jay_Shah and welcome to the community. Have you had the chance to go through our documentation regarding gRPC proxy

Hi @Olu Yes I did. and I also tried flush_interval to few msecs configs as mentioned in document.

So you tried setting flush_interval to 1 and it didn’t make a difference? What’s your gateway version?

The only other thing I can suggest is to enable_websockets and find out if upstream is setting a streaming header

Yes. That did not help much. Gateway version which I am using is, v4.0.1.

Just now I got it working, by doing some changes on Tyk Gateway.

  1. When we are using grpc.ServeHTTP methods with the http responders, http responder expects (http.Flusher).Flush() be implemented, However, Tyk wraps http responder in customResponseWriter and hence, Flush() is not lifted.

So, Lifting ResponseWriter.(http.Flusher).Flush() through customResponseWriter helped me.

func (w *customResponseWriter) Flush() {
w.ResponseWriter.(http.Flusher).Flush()
}

Please suggest if such code changes at Tyk Gateway are suggestable?

Could you open a Github issue describing the problem and then create a pull request against that with the fix.

Sure. I tried and facing below auth issue.

Can you please let me know, how to get contributor access.

Hi,

I’m sorry you won’t be able to push to the tyk tree. If you fork the tyk repo you can create a pull request from your repo to tyk. It will then be reviewed by the engineering team.

Thanks for taking the time to do this, we really appreciate your contribution!

Cheers,
Pete

Hi @Pete Thanks for info. As per guidelines have created the Pull Request,