Skip to content
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

How to implement router? #462

Open
mzdk100 opened this issue Jul 16, 2024 · 4 comments
Open

How to implement router? #462

mzdk100 opened this issue Jul 16, 2024 · 4 comments

Comments

@mzdk100
Copy link

mzdk100 commented Jul 16, 2024

I need to define different services to handle different tasks, such as:

#[tarpc::service]
pub trait UserService {
    async fn login(name: String);
}

#[tarpc::service]
pub trait OrderService {
    async fn query(name: String);
}

The current problem is how to register these two services into the framework, and then create clients using 'UserServiceClient::new' and 'OrderServiceClient::new' and call them?

@tikue
Copy link
Collaborator

tikue commented Aug 12, 2024

Thanks for the question! Tarpc doesn't natively support registering multiple services on a single server. I can suggest a few options:

@mzdk100
Copy link
Author

mzdk100 commented Aug 12, 2024

The "multiplexing transport" solution is good, but it requires writing a lot of code. Can't the tarpc framework handle these things itself?
The microservice framework should be designed to be modular so that we can organize the code more conveniently.

@tikue
Copy link
Collaborator

tikue commented Aug 12, 2024

The main reason tarpc can't easily support native multiplexing is because the transport is typically generic over the request/response type.

Could the multiplexing code be written generically as a library? Then it wouldn't have to be duplicated by each user. If it were proven popular enough, perhaps it could be merged into tarpc.

@mzdk100
Copy link
Author

mzdk100 commented Aug 12, 2024

Currently, I'm using the quic-rpc library which can meet my need for modularizing the code, but writing code is not as concise as using the tarpc framework.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants