Giter VIP home page Giter VIP logo

Comments (3)

lquerel avatar lquerel commented on May 20, 2024

By patching the #[madsim::service] macro code I was able to get an example that works. The modification is to change the signature of the serve_on method to an Arc instead of an Endpoint. This allows me to also pass a clone of Arc to my service to allow communication with another service. However, I think the approach could be improved by making a slightly more complex modification.

Approach compatible with the existing API: the idea would be to provide a method to retrieve a reference to the current endpoint.

Approach requiring a change in the API: the idea would be to change the signature of the methods annotated with #[rpc] and to add as first parameter a reference on the current endpoint.

I can see how to implement the second approach. For the first one I'm not sure how to do it.

What do you think about it?

from madsim.

wangrunji0408 avatar wangrunji0408 commented on May 20, 2024

Hi, thanks for your interest on this project!

Microservices is definitely a scenario we want to support. But since we haven't applied madsim to such a project, the API of this part is not mature enough to use.

For this problem, personally I prefer to change the signature of the serve_on method to an Arc<Endpoint>. Or one more step, we can make Endpoint itself cheaply clonable, as several other crates did. I believe this would be more friendly to developers.

For the 2 approaches you mentioned, I'm not sure whether we should encourage users to reuse the endpoint from current service to communicate with another one. Because usually they would create a new endpoint for this. If only considering these 2 approaches, I would choose the first one but it doesn't seem to work. (The service does not own an endpoint so it's impossible to retrieve one.) The second approach changes the signature of all RPC handlers, so doesn't look to be a good solution to me.

Overall, in this scenario, I recommend putting an endpoint into the service structure to communicate with other service. It is OK whether itself is serving on the same endpoint or not.

If I can solve this problem, I will submit a PR containing an example of a microservices topology communicating via RPC and running on several simulated nodes. I think this kind of complete example doesn't exist yet in the repo and it would probably save time for future users. Feel free to point me to such an example if it exists.

Unfortunately we don't have such an example right now. I was trying to migrate madraft as an example but it has not finished yet. You are welcome to submit PRs for any improvements!

from madsim.

lquerel avatar lquerel commented on May 20, 2024

Thank you for your feedback. I will submit a PR in the next few days with this example and modification.

from madsim.

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.