Skip to content

Adds the option to use a pre configured RSocketRequester #498

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

iromu
Copy link
Contributor

@iromu iromu commented Sep 28, 2022

This PR adds support to reuse a RSocketRequester object, with the purpose of reusing its load balancing features, and to avoid duplicating code in case the applciations uses GraphQL over RSocket and RSocket clients.

As described on Issue #497

@pivotal-cla
Copy link

@iromu Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Sep 28, 2022
@pivotal-cla
Copy link

@iromu Thank you for signing the Contributor License Agreement!

@rstoyanchev rstoyanchev self-assigned this Sep 29, 2022
@rstoyanchev rstoyanchev added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Sep 29, 2022
@rstoyanchev rstoyanchev added this to the 1.0.3 milestone Sep 29, 2022
Copy link
Contributor

@rstoyanchev rstoyanchev left a comment

Choose a reason for hiding this comment

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

The challenge with accepting a fully built RSocketRequester is that it becomes mutually exclusive with all other builder methods. So you have to prepare your requester externally and bypass the builder essentially.

I think it would be better if we exposed the same as what is available on the RSocketRequester.Builder since RSocketGraphQlClient.Builder is meant to be just a convenience wrapper around it. In other words:

interface Builder<B extends Builder<B>> extends GraphQlClient.Builder<B> {

    // ...

    B transports(Publisher<List<LoadbalanceTarget>> targetPublisher, LoadbalanceStrategy loadbalanceStrategy);

}

Do you want to rework the PR along those lines, or otherwise I can also take it from here?

@iromu
Copy link
Contributor Author

iromu commented Sep 29, 2022

I agree it is an edge case that an application will reuse a RSocketRequester. The code works, the only problem I saw was having to set a Json Decoder by default.

Adding transports as a builder method looks more aligned with the current code. Let me update the PR to see how the code will look like.

@iromu
Copy link
Contributor Author

iromu commented Sep 29, 2022

It does looks better.

@Bean
public RSocketGraphQlClient rSocketGraphQlClient(RSocketGraphQlClient.Builder<?> builder,
                                                 ReactiveDiscoveryClient discoveryClient
) {
    Flux<List<LoadbalanceTarget>> servers = getServers(discoveryClient, "GRAPHQL-MONGO");
    return builder
        .transports(servers, new RoundRobinLoadbalanceStrategy())
        .route("graphql")
        .build();
}

@iromu iromu requested a review from rstoyanchev September 29, 2022 18:06
Copy link
Contributor

@rstoyanchev rstoyanchev left a comment

Choose a reason for hiding this comment

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

Mostly good.

There is a small detail missing, that the loadbalance details will need to be passed to the DefaultRSocketGraphQlClient and then used in the mutate method, or otherwise mutate wouldn't work well if used. That's relatively minor though. I could take it from here.

@iromu
Copy link
Contributor Author

iromu commented Oct 10, 2022

Feel free to take it from here and apply any styling preference.

@iromu iromu requested a review from rstoyanchev October 10, 2022 16:08
rstoyanchev pushed a commit that referenced this pull request Oct 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants