当前位置:网站首页>Microservice practice based on rustlang
Microservice practice based on rustlang
2022-06-13 03:15:00 【flyweight_ visitor】
be based on Rustlang Microservice practice of
The goal is
adopt 1 A simple scenario , Validation based on Rust The feasibility and challenges of building micro services .
framework
The code structure
{Workspaces}/{top level workspace}/{micro-service workspace}/{micro-service component package}
| Structure name | example |
|---|---|
| Workspaces | rustlangws |
| Top level workspace | rustlang-hacking-microservice-1 |
| micro-service workspace | hacking_news |
| micro-service component package | hacking_news_app |
| micro-service component package | hacking_news_domain |
| micro-service component package | hacking_news_infra |
| micro-service component package | hacking_news_migrations |
| micro-service workspace | hacking_trading |
| micro-service component package | hacking_trading_app |
| micro-service component package | hacking_trading_domain |
| micro-service component package | hacking_trading_infra |
| micro-service component package | hacking_trading_migrations |

Practice practice
Brief description of development tool chain
- Rustup and Cargo
- Visual studio code
- Github
Project creation
Create project
by Rust Development and setup 1 A separate workspace , Name it rustlangws. Under the workspace are different microservices , Microservices are isolated by directories . Within each microservice , The different components are 1 Independent Rust project .
- Create a workspace
cd ~
mkdir -p Projects/rustlangws/
- Create an empty Github The project is the root project of the microservice project
https://github.com/AllenShi/rustlang-hacking-microservice-1
- Clone The root project of the microservice project
cd Projects/rustlangws/
git clone [email protected]:AllenShi/rustlang-hacking-microservice-1.git
- Create isolated directories for specific microservices in the root project
cd rustlang-hacking-microservice-1/
mkdir -p hacking_news
mkdir -p hacking_trading
stay hacking_news and hacking_trading Under the directory of 1 individual Cargo.toml, Describe the microservice components contained in the workspace of each specific microservice .
hacking_news/Cargo.toml
[workspace]
members = [
"hacking_news_app",
"hacking-news_domain",
"hacking_news_infra",
"hacking_news_migrations"
]
hacking_trading/Cargo.toml
[workspace]
members = [
"hacking_trading_app",
"hacking_trading_domain",
"hacking_trading_infra",
"hacking_trading_migrations"
]
- Create the required for the microservice Rust project ( Service components )
cd hacking_news
cargo new --bin hacking_news_app
cargo new --lib hacking_news_domain
cargo new --lib hacking_news_infra
cargo new --lib hacking_news_migrations
cd hacking_trading
cargo new --bin hacking_trading_app
cargo new --lib hacking_trading_domain
cargo new --lib hacking_trading_infra
cargo new --lib hacking_trading_migrations
Project development
open Visual Studio Code, Make sure Rust extension Is already installed . If not installed , Can pass View -> Command Palette … -> Extensions: Install Extensions …, And then the search Rust, Choose to install .
stay VSC install Debugger Tools CodeLLDB(Native debugger based on LLDB.)

install Rust Test Lens

The project build
- add to Rust Workspace to VSC The workspace . This can be done by File -> Add Folder to Workspace …
- Add the root directory of the project to VSC The workspace rustlang-hacking-microservice-1
- Add the of each microservice item independently rust Workspace to VSC The workspace : rustlang-hacking-microservice-1/hacking_news, rustlang-hacking-microservice-1/hacking_trading

- ( Optional ) stay VSC Add... For each microservice item config
Click on the left side of the Run, Select the target micro service in the list that appears , increase config, Generate or update launch.json

{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in library 'rust_playground'",
"cargo": {
"args": [
"test",
"--no-run",
"--lib",
"--package=rust_playground"
],
"filter": {
"name": "rust_playground",
"kind": "lib"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug executable 'rust_playground'",
"cargo": {
"args": [
"build",
"--bin=rust_playground",
"--package=rust_playground"
],
"filter": {
"name": "rust_playground",
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
}
]
}
- Build project or debug run
cargo build

- Check the built binaries
ls -alh target/debug/
total 55584
drwxr-xr-x 18 sjl staff 576B 11 30 22:37 .
[email protected] 5 sjl staff 160B 11 30 22:24 ..
-rw-r--r-- 1 sjl staff 0B 11 30 22:24 .cargo-lock
drwxr-xr-x 249 sjl staff 7.8K 11 30 22:33 .fingerprint
drwxr-xr-x 60 sjl staff 1.9K 11 30 22:33 build
drwxr-xr-x 569 sjl staff 18K 11 30 22:37 deps
drwxr-xr-x 2 sjl staff 64B 11 30 22:24 examples
-rwxr-xr-x 2 sjl staff 21M 11 30 22:37 hacking_news_app
-rw-r--r-- 1 sjl staff 800B 11 30 22:37 hacking_news_app.d
lrwxr-xr-x 1 sjl staff 26B 11 30 22:37 hacking_news_app.dSYM -> deps/hacking_news_app.dSYM
-rwxr-xr-x 2 sjl staff 6.2M 11 30 22:35 hacking_news_migrations
-rw-r--r-- 1 sjl staff 348B 11 30 22:37 hacking_news_migrations.d
lrwxr-xr-x 1 sjl staff 33B 11 30 22:35 hacking_news_migrations.dSYM -> deps/hacking_news_migrations.dSYM
drwxr-xr-x 6 sjl staff 192B 11 30 22:35 incremental
-rw-r--r-- 1 sjl staff 225B 11 30 22:37 libhacking_news_domain.d
-rw-r--r-- 2 sjl staff 109K 11 30 22:35 libhacking_news_domain.rlib
-rw-r--r-- 1 sjl staff 330B 11 30 22:37 libhacking_news_infra.d
-rw-r--r-- 2 sjl staff 262K 11 30 22:35 libhacking_news_infra.rlib
Project test
- Run test cases under the project
cd rustlangws/rustlang-hacking-microservice-1/hacking_news
cargo test
Project deployment
- Container-based deployment
- establish Dockerfile
- Create build scripts
cd rustlangws/rustlang-hacking-microservice-1/hacking_news
mkdir -p build
cross-compilation.sh
docker-build.sh
start-docker.sh
- be based on K8S Deployment of
- Create deployed YAML spec
- Create deployed scripts
cd rustlangws/rustlang-hacking-microservice-1/hacking_news
k8s-deployment.sh
mkdir -p build/spec
hacking_news_app_v1_deployment.yaml
hacking_news_app_v1_svc.yaml
Problem solving (Troubleshooting)
- Cargo build Command line execution stops , Show "Blocking waiting for file lock on the registry index"
Solution :
- Check if there are multiple processes compiling the same project at the same time . such as VSC Perform compilation in the background , The command line is also compiling . here , close VSC
2) Clear file lock
rm -rf ~/.cargo/registry/index/*
rm -rf ~/.cargo/.package-cache
- Can't find crate postgres, Show “can’t find crate”
Solution
- stay crates.io Site search postgres, The display version is 0.18.1
- stay Cargo.toml Of dependencies The version displayed inside is lower than this version number , Update version number , Recompile it
Project source code
https://github.com/AllenShi/rustlang-hacking-microservice-1
summary
Reference resources
边栏推荐
- Linked list: reverse linked list
- Ijkplayer source code - setting option 2
- MySQL index bottom layer (I)
- Vs Code modify default terminal_ Modify the default terminal opened by vs Code
- Wechat applet obtains the current location (startlocationupdate, onlocationchange, offlocationchange)
- Ijkplayer source code -- mnatemediaplayer of ijkmediaplayer
- Sparksql of spark
- Add Yum source to install php74
- Flutter reports an error type 'Int' is not a subtype of type 'string' wonderful experience
- JMeter quick start
猜你喜欢

Typical application of ACL

Mvcc and bufferpool (VI)

2021-08-30 distributed cluster

Es and kibana deployment and setup

Applet image component long press to identify supported codes

Wechat applet switch style rewriting

Available types in C #_ Unavailable type_ C double question mark_ C question mark point_ C null is not equal to
![HEAP[xxx.exe]: Invalid address specified to RtlValidateHeap( 0xxxxxx, 0x000xx)](/img/c9/884aa008a185a471dfe252c0756fc1.png)
HEAP[xxx.exe]: Invalid address specified to RtlValidateHeap( 0xxxxxx, 0x000xx)
![[JVM Series 5] JVM tuning instance](/img/29/271fa25a338ee1268f7bce58673e11.jpg)
[JVM Series 5] JVM tuning instance

QML connecting to MySQL database
随机推荐
Install MySQL database
视频播放屡破1000W+,在快手如何利用二次元打造爆款
Data Governance Series 1: data governance framework [interpretation and analysis]
Reading notes of effective managers
Scala implements workcount
Four ways of array traversal in PHP
Radium laser radar C16 data to PCD (based on ROS)
Es and kibana deployment and setup
Few-shot Unsupervised Domain Adaptation with Image-to-Class Sparse Similarity Encoding
MySQL index
开源-校园论坛和资源共享小程序
Introduction to Sitemap_ Sitemap online generation and sorting
Hash table: the time complexity of insert, delete and random access is O (1)
JVM class loading (I)
How to manage the IT R & D department?
HEAP[xxx.exe]: Invalid address specified to RtlValidateHeap( 0xxxxxx, 0x000xx)
On the limit problem of compound function
Five old code farmers, program life review: peace of mind is not the place to go
Beginner development process_ Project development FAQs
Differences between XAML and XML