In an HTTP request/response scenario, I guess it doesn't matter to the client who responds to the requests (how would he tell anyway).
In short, I want to go from this :
Client
↓ ↑
Nginx
↓ ↑
ServerA
↓ ↑
ServerB
To this :
Client
↓ ↑
Nginx ↖
↓ ↖
ServerA ↖
↓ ↗
ServerB
Since serverB already has the response and no additional treatment will be done, I would like to bypass the serverA, but should go through nginx if possible (to use compression for instance).
Specifically I would like to know more about :
the nginx configuration necessary (if any)
does the protocol exchange between serverA and ServerB has to be special ?
the context that has to be passed around for this to happen ? Also, what happens if they use different languages (in my case Clojure and Scala).
A small sample example would be very welcome (preferably Clojure, Scala, Java, Node.js - any language as long as it's readable).
I'm sure your case can be implemented with nginx-clojure. Last year somebody did similar but more complex things with nginx-clojure. And there 's nothing to do with protocol exchange between serverA and ServerB.
hijack!
to get a NginxHttpServerChannel say ch
, put ch
into a map with key say req-uuid
. So we can use ch
to send response data later. Sends nginx url, req-uuid and other data to ServerA.nginx-url
, req-uuid
and other data to ServerB.req-uuid
and response to nginx by another url which is different with the first step, e.g. '/asynNotfifyHandler'ch
and uses it to send the response. If we have more than one nginx worker processes we need use broadcast!
to broadcast repsonse event and use on-broadcast!
to get the response event in the nginx worker process who holds the NginxHttpServerChannel ch
and use it to send the response to the original client.Here is an example about channel sub/pub.
BTW We also can use sub/pub from redis instead of broadcast!
and on-broadcast!
from nginx-clojure. e.g. in the first content handler we sub a topic of redis and then server B pub a response message to the same topic of redis. Finally use NginxHttpServerChannel ch
to send the response to the original client.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments