Comments (3)
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.
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.
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)
- bug: s3 simulator returns unexpected error in delete_objects
- How to add madsim support for opendal? HOT 3
- print/validate MADSIM_CONFIG_HASH HOT 1
- Docs: Add caveat about madsim reproducibility HOT 3
- How to deal with thread spawned outside of madsim simulation HOT 2
- include original crate's version HOT 11
- docs: more detailed explanation about how and why to patch deps
- feature: support timeout in tonic requests HOT 2
- feature request: support `btree_map` api for Builder
- Enhancing Determinism by Forking Processes
- Improving behaviour to failed socket address parsing
- wrong `tokio::runtime::Runtime::enter` implementation HOT 4
- panic if spawn when task drop HOT 2
- patch `tokio_stream` HOT 1
- Implement `tokio::task::AbortHandle::is_finished` HOT 2
- Tags are missing after release `v0.2.15` HOT 1
- `tokio::time::sleep(Duration::ZERO)` is not simulated properly HOT 1
- Creating multiple runtimes with the same seed yields different random values HOT 2
- Check the result of the function in `check_determinism` HOT 1
- unaligned pointer for rand 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 madsim.