looking for good solution to invoke http client method in a bean (i.e. MDB, session)
I would like to invoke http client method (HTTP PUT, GET, et al) within a bean, but I want these beans, either MDB or stateless session bean, run as quick as possible (with extreme short life time).
---[ejb request]--> bean -----[http request]----> host
Problem is, the HTTP connection is too slow (especially when connecting to slow hosts). Take MDB for example, due to HTTP latency, the MDB run too long, and the queue is quickly stalled with continuing coming messages. (Message producer is faster than http method invocation.)
How can I solve such problem?
- using NIO http client? would it help?
- open extra Th开发者_开发百科reads to execute http invocation? (but running explicit thread in bean is not recommended in Java EE)
- some async http client? is there any such libs? don't they use Thread?
Using a NIO-based client is not going to resolve change the fact that your connections and target hosts are too slow. Full stop. It sounds like you have a fundamental problem that can be solved by other methods:
- Time out the connections. Only viable if your clients can fail.
- Increase concurrency, the number of client connections running at once. This seems like the most logical step to me.
精彩评论