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

how to make an async call before proxy to another server? #7

Closed
Taymindis opened this issue Nov 29, 2018 · 1 comment
Closed

how to make an async call before proxy to another server? #7

Taymindis opened this issue Nov 29, 2018 · 1 comment
Labels
help wanted Extra attention is needed question Further information is requested

Comments

@Taymindis
Copy link
Owner

Taymindis commented Nov 29, 2018

Top picked emailed question:

I have a bunch of requests need to call at async and proxy the result to another server How can I do that?

@Taymindis
Copy link
Owner Author

Taymindis commented Nov 29, 2018

For this answer:

Currently link function module subrequest is only supporting sequential call (sync), and it is still under beta version.

I will recommend you try to use aio threads to pass request into your apps layer, and make async(future) call in your apps. After that add the result into headers input for proxy request purpose.

Assume that you are using c++ application linking, there are many async http client in c/c++. such as
Boost.Asio
backcurl
restclient-cpp.

void bunchOfRequests(ngx_link_func_ctx_t* ctx) {
   //  ( "Async calling");
	http.AsyncCall(.........);
 // Request done, add to header for next request
   ngx_link_func_add_header_in(ctx, "myResult", strlen("myResult"), result->data, result->len);
   ngx_link_func_add_header_in(ctx, "myResult2", strlen("myResult2"), result2->data, result2->len);
   ngx_link_func_add_header_in(ctx, "myResult3", strlen("myResult3"), result3->data, result3->len);

  //   if you are proxy route to another, do not make response content, that's all !!
}
aio threads=myThreadPools;
location /oneBunchRequestAndRoute {
 ngx_link_func_call 'bunchOfRequests';  
 proxy_pass http://xxxxxxxxxx;
}

@Taymindis Taymindis added help wanted Extra attention is needed question Further information is requested labels Nov 29, 2018
@Taymindis Taymindis changed the title how to make an aync call parallely before proxy to another server? how to make an async call before proxy to another server? Nov 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant