Giter Site home page Giter Site logo

Comments (13)

rmichela avatar rmichela commented on May 23, 2024 3

I've taken a first stab at implementing simple unary request parameters. Please take a look @ktoso @bsideup .

from reactive-grpc.

cbornet avatar cbornet commented on May 23, 2024 2

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.

rmichela avatar rmichela commented on May 23, 2024 1

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.

ktoso avatar ktoso commented on May 23, 2024 1

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.

https://github.com/akka/akka-grpc/blob/master/plugin-tester-scala/src/main/scala/example/myapp/helloworld/GreeterServiceImpl.scala#L17

Keep it simple :-)

from reactive-grpc.

ktoso avatar ktoso commented on May 23, 2024 1

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.

rmichela avatar rmichela commented on May 23, 2024 1

Ok. If this change aligns with other reactive libraries, it makes sense.

from reactive-grpc.

rmichela avatar rmichela commented on May 23, 2024 1

Interesting idea...care to submit a PR? 😁

from reactive-grpc.

bsideup avatar bsideup commented on May 23, 2024

@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.

bsideup avatar bsideup commented on May 23, 2024

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.

bsideup avatar bsideup commented on May 23, 2024

@ktoso but the argument is not Future, right? While reactive-grpc always demands the arguments to be Mono (Future-ish)

from reactive-grpc.

bsideup avatar bsideup commented on May 23, 2024

@rmichela looks good as a first step, removes a bunch of pain already πŸ‘

from reactive-grpc.

rmichela avatar rmichela commented on May 23, 2024

looks good as a first step

Is there a second step? πŸ˜‰

from reactive-grpc.

bsideup avatar bsideup commented on May 23, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.