Comments (13)
I've taken a first stab at implementing simple unary request parameters. Please take a look @ktoso @bsideup .
from reactive-grpc.
I had a look at other rx-streams libs (eg. spring-data) and they indeed expose both a reactive and non-reactive argument API. Moreover, the reactive argument method takes a Publisher which I believe is better as itβs more generic. So we should do the same. WDYT @rmichela ?
from reactive-grpc.
I'm sort of on the fence with this one.
I can appreciate the elegance of method signatures that align with the types you have, but I'm not convinced that generating (and maintaining) a second Mono/Single client stub method to save from typing Mono.just(
is justified.
Perhaps I'm being overly conservative. Please feel free to challenge me. π
from reactive-grpc.
I believe I agree with @rmichela.
In fact, in akka/akka-grpc this is what we choose to do as well;
Unary calls are represented by Futures or CompletionStage (well, or just parameter to the to-be-implemented-function); and streaming calls are represented by our Reactive Streams counter-parts which are Source in this specific example.
Keep it simple :-)
from reactive-grpc.
I see what you mean now; correct, incoming parameter is just a T
, not a Future[T]
. We saw no need to keep the potentially delayed thing there -- once we gather the element, we invoke user code, no reason to keep it wrapped there indeed.
from reactive-grpc.
Ok. If this change aligns with other reactive libraries, it makes sense.
from reactive-grpc.
Interesting idea...care to submit a PR? π
from reactive-grpc.
@rmichela maintainance is of course a good argument, but for this one IMO it's rather minor :)
reactive-grpc
is a great library to generate reactive-ready clients from protobuf definitions.
In fact, in one of our projects we suggest to use it "as is" without providing any additional client libraries around it.
But when you look at it, it looks strange that the user has to wrap arguments with Mono:
https://github.com/bsideup/liiklus/blob/dee36132855870a37f87b8c8dd42cc457d4d2118/examples/java/src/main/java/com/example/Consumer.java#L59
I saw your compose
-style usages, but it confuses the end users.
Other reactive libraries (like reactor-netty) offer non-reactive arguments when it's not needed:
reactor-netty example:
https://github.com/reactor/reactor-netty/blob/930d748d51fa3b6129d4346fe3b062b654fd3818/src/test/java/reactor/ipc/netty/http/ClientServerHttpTests.java#L291
akka streams http example:
https://github.com/akka/akka-http/blob/ca28e2db878487c2a4bd7d34cb78139f64a4d70d/docs/src/test/java/docs/http/javadsl/HttpClientExampleDocTest.java#L182
it's also possible (in future) to optimize such calls and remove Mono -> un-Mono
chain when the source of argument is not reactive.
Forcing it to be Mono
creates unnecessary feeling that the argument has to be cold, while most of gRPC arguments are hot inline builders
TL;DR:
I'm a huge fan of reactive APIs but IMO they should be reactive only when necessary.
maybe @smaldini @simonbasle @akarnokd @ktoso have something to add.
from reactive-grpc.
After some thoughts I even think that the generated implementation should look like that:
public Flux<...> doSomething(Mono<SomeType> argument) {
return argument.flatMapMany(this::doCall);
}
public Flux<...> doSomething(SomeType argument) {
return doCall(argument);
}
This way there is no Mono -> un-Mono
chain and it supports both scenarios :)
from reactive-grpc.
@ktoso but the argument is not Future, right? While reactive-grpc
always demands the arguments to be Mono (Future-ish)
from reactive-grpc.
@rmichela looks good as a first step, removes a bunch of pain already π
from reactive-grpc.
looks good as a first step
Is there a second step? π
from reactive-grpc.
@rmichela
bsideup/liiklus@20fd7ef
So. Much. Better. π Thanks!
A second step, as I see it, is to do it like this:
public Flux<...> doSomething(Mono<SomeType> argument) {
return argument.flatMapMany(this::doCall);
}
public Flux<...> doSomething(SomeType argument) {
return doCall(argument);
}
Good for performance critical apps
from reactive-grpc.
Related Issues (20)
- How do you configure how much data is buffered on the producer side? HOT 1
- Wrong manifest main class rx3grpc HOT 4
- Backpressure Demo has compile error on Windows
- stub.invoke().retry() throws exception HOT 1
- Async resource cleanup failed after onComplete / call already closed HOT 2
- Add onDiscard hook support to AbstractStreamObserverAndPublisher
- host_javabase is deprecated HOT 1
- Possible to have non-publisher for RPC method parameter? HOT 2
- In ManyToOne and ManyToMany, remote method is called before the client subscribe
- project still activeοΌ HOT 1
- UnsupportedOperationException thrown in the generated stub with Java 17 HOT 2
- Unexpedted error log HOT 1
- Dropped Error on Bidi Stream After Broken TCP Connection HOT 2
- Subscription Should be Cancelled on Interceptor Close HOT 3
- How about a new stable release? HOT 14
- Migrate reactive-grpc to grpc-ecosystem HOT 2
- Indeterminate cancel or error when streaming bidirectionally
- Question: how can Spring reactive-grpc support credentials on server HOT 2
- Bazel demo does not compile HOT 1
- How to customize ClientInterceptor and ServerInterceptor HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from reactive-grpc.