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
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.
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?
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!