"retrofeign" retrofits ... retrofit's async layer onto feign
This project has a lot of users, and needs some help I think. What if we tried to leverage code that has a nice design to extend the life a bit.
My theory is that we could make "retrofeign" which would allow the same contract parsing that feign existing users have, but be able to employ retrofit async layering (ex rxjava)
Ex. it would look like..
Feign feign = RetroFeign.builder()
... // normal things
.callAdapterFactory(RxJava2CallAdapterFactory.create())
.target(MyService.class, "https://example.com");
interface MyService {
@RequestLine("GET /user")
Observable<User> getUser();
}
The call adapter factory won't always be portable as it relies on Retrofit. However the code there is relatively straightforward, and some of the call adapters don't actually use the retrofit instance at all. At any case I think we could reuse the Call adapters with less effort than starting something from scratch.
https://github.com/square/retrofit/blob/master/retrofit/src/main/java/retrofit2/CallAdapter.java
It might not work, but seems like a good way to provide sustainable options to people. For example, when using okhttp client we could use this to reasonably easily create guava rxjava or other types of async things.
thoughts?
cc @jakewharton @swankjesse
okhttp3 also has an async api. just needs an threadpool, no need to wrap it so this may be a good general solution for asyncing things.
I've had a similar idea for Spring's WebClient. This would not only be asynchronous but non-blocking.
Neat!
BTW, today Retrofit uses a thread for each in-flight request. But there is a plan for non-blocking I/O to eventually make its way into Okio/OkHttp/Retrofit. But not NIO. Instead I wanna do coroutines, either with Quasar, JVM coroutines, or perhaps Kotlin! There are no plans to ever support NIO-style async where you get callbacks with chunks of a response; I find that programming model completely distasteful.
@kdavisk6 let's create repository for reactor feign under OpenFeign similar to what was done for Vert.x
@kdavisk6 Just committed into feign-reactive.
There are 2 modules:
feign-reactive-core - basic framework with retry/log/status/interceptor handling
feign-reactive-fake-impl - draft non reactive implementation that looks like reactive :) (but ReactivityTest fails)
I look at the PR, I was thinking... may be, the default implementation should be only dealing with Future and then we could have reactive implementation for reactor, Callbacks and other possible implementations.... how does that feel?
Agree. Would be better to rename it to feign-reactor
I was going to suggest the same thing.
renamed modules/packages to reactor
@kdavisk6 How and where can I publish this artifacts so I may proceed with implementation based on Spring's WebClient
Do you wanna cut a release?! I guess I can help with that....
Shall we aim to release at same time as 10
I’d like to review it a little more closely. I’ll do that today. If 10 is ready we can do that today as well
@velo and @kptfh, I see that you have a number of classes that are part of feign-core copied and replicated in feign-reactive-core. I think we should refactor those out so that feign-reactive-core can stay in sync with feign-core. I'm going to take a stab at this and I'll create a PR for you all to review.
In addition, we do still have some housekeeping to do on the project, we need to enable travis and configure it to deploy once we have a release ready.
Hi @kdavisk6, should I perform those steps you mentioned in your comment (to enable travis and configure it to deploy once we have a release ready) ?
Do you still plan to introduce some changes?
Yes, I have some changes I am working on, but we don't need to wait to move forward. My changes are centered around general feign compatibility and updates for feign 10.x.
With regards to travis and nexus, I think @velo and I need to reach out to a few other folks to get the background and information we need to get this project set up. Once we do, we'll add some documentation and consider releasing a MILESTONE release for this.
Travis has been abled on the feign-reactive project.