Skip to content

Reactive Wrapper Support#795

Merged
velo merged 1 commit into
OpenFeign:masterfrom
kdavisk6:reactive-wrappers
Oct 13, 2018
Merged

Reactive Wrapper Support#795
velo merged 1 commit into
OpenFeign:masterfrom
kdavisk6:reactive-wrappers

Conversation

@kdavisk6

@kdavisk6 kdavisk6 commented Sep 24, 2018

Copy link
Copy Markdown
Member

Adding support for Reactive Streams Publisher return types. Support
is provided through the ReactiveInvocationHandler and follows a similar
pattern used by feign-hystrix. Each method invocation is wrapped in a
Callable, which is then wrapped into the appropriate Reactive Streams
Publisher, as defined in the builder and the return type of the method.

This approach is not "reactive all the way down". The requests are still
executed via a regular Client and are synchronous. However, it is possible
to still take advantage of the backpressure, scheduling, and functional support
provided by the library implementations.

Limitations: Streams are not supported and Iterable responses are not treated
reactively. Iterables must be explicitly cast into a reactive type.

Special thanks to @ilaborie for doing much of the upfront work. See #491 and #622

@kdavisk6 kdavisk6 added enhancement For recommending new capabilities waiting for feedback Issues waiting for a response from either to the author or other maintainers labels Sep 24, 2018
@kdavisk6 kdavisk6 requested a review from velo October 10, 2018 12:30

@velo velo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I liked, add just 2 minor suggestions...

Sorry for taking so long

if (library == null) {
throw new IllegalStateException("A Reactive Streams Library has not been specified");
}
super.contract(new ReactiveDelegatingContract(this.contract));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would recommend checking if contract is an instance of ReactiveC and only warp of not

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.

if (ReactiveStreamsLibrary.REACTOR == this.library) {
return new ReactorInvocationHandler(target, methodHandlerMap);
} else if (ReactiveStreamsLibrary.RXJAVA == this.library) {
return new RxJavaInvocationHandler(target, methodHandlerMap);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be inject on the builder so becomes a configuration a give flexibility?!

ReactiveFeign.builder()
   .withInvocationHandler( RxJavaInvocationHandler::new )
...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would allow ReactiveStreamsLibrary to be removed...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I might do is create custom builders instead. I'll give it a try.

Adding support for Reactive Streams `Publisher` return types.  Support
is provided through the `ReactiveInvocationHandler` and follows a similar
pattern used by `feign-hystrix`.  Each method invocation is wrapped in a
`Callable`, which is then wrapped into the appropriate Reactive Streams
`Publisher`, as defined in the builder and the return type of the method.

This approach is not "reactive all the way down".  The requests are still
executed via a regular `Client` and are synchronous.  However, it is possible
to still take advantage of the backpressure, scheduling, and functional support
provided by the library implementations.

Limitations: Streams are not supported and Iterable responses are not treated
reactively.  Iterables must be explicitly cast into a reactive type.

Reworked Builders and removed the need for the enumerator
@kdavisk6

Copy link
Copy Markdown
Member Author

@velo Created specific Builders for Reactor and RxJava and removed the libraries enum

@velo velo merged commit 07a41b0 into OpenFeign:master Oct 13, 2018
@kdavisk6 kdavisk6 added this to the 10.1.0 milestone Oct 14, 2018
@velo velo mentioned this pull request Oct 19, 2018
@kdavisk6 kdavisk6 deleted the reactive-wrappers branch November 14, 2018 13:31
velo pushed a commit that referenced this pull request Oct 7, 2024
Adding support for Reactive Streams `Publisher` return types.  Support
is provided through the `ReactiveInvocationHandler` and follows a similar
pattern used by `feign-hystrix`.  Each method invocation is wrapped in a
`Callable`, which is then wrapped into the appropriate Reactive Streams
`Publisher`, as defined in the builder and the return type of the method.

This approach is not "reactive all the way down".  The requests are still
executed via a regular `Client` and are synchronous.  However, it is possible
to still take advantage of the backpressure, scheduling, and functional support
provided by the library implementations.

Limitations: Streams are not supported and Iterable responses are not treated
reactively.  Iterables must be explicitly cast into a reactive type.

Reworked Builders and removed the need for the enumerator
velo pushed a commit that referenced this pull request Oct 8, 2024
Adding support for Reactive Streams `Publisher` return types.  Support
is provided through the `ReactiveInvocationHandler` and follows a similar
pattern used by `feign-hystrix`.  Each method invocation is wrapped in a
`Callable`, which is then wrapped into the appropriate Reactive Streams
`Publisher`, as defined in the builder and the return type of the method.

This approach is not "reactive all the way down".  The requests are still
executed via a regular `Client` and are synchronous.  However, it is possible
to still take advantage of the backpressure, scheduling, and functional support
provided by the library implementations.

Limitations: Streams are not supported and Iterable responses are not treated
reactively.  Iterables must be explicitly cast into a reactive type.

Reworked Builders and removed the need for the enumerator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement For recommending new capabilities waiting for feedback Issues waiting for a response from either to the author or other maintainers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants