当前位置:网站首页>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
边栏推荐
- QML connecting to MySQL database
- brew工具-“fatal: Could not resolve HEAD to a revision”错误解决
- Keil removes annoying st link update tips
- 【同步功能】2.0.16-19 版本都有同步功能修复的更新,但未解决问题
- MySQL index optimization (4)
- JVM virtual machine stack (III)
- JVM class loading (I)
- Radium laser radar C16 data to PCD (based on ROS)
- Transaction processing in PDO
- Least recently used cache (source force deduction)
猜你喜欢
MySQL index optimization (4)
SQL execution process in MySQL (3)
MySQL index bottom layer (I)
MySQL transactions and locks (V)
【pytorch 记录】pytorch的变量parameter、buffer。self.register_buffer()、self.register_parameter()
C simple understanding - arrays and sets
Installing the IK word breaker
Querywrapper constructor method
MySQL 8.0 installation free configuration method
Mvcc and bufferpool (VI)
随机推荐
Data Governance Series 1: data governance framework [interpretation and analysis]
Introduction to Sitemap_ Sitemap online generation and sorting
Explode and implode in PHP
English grammar_ Mode adverb position
Exercise 8-3 rotate array right
Es and kibana deployment and setup
Linked list: the entry node of the link in the linked list
Mvcc and bufferpool (VI)
通过Web ETL统一调度和管理DataX任务
Vs Code modify default terminal_ Modify the default terminal opened by vs Code
Linked list: adding numbers in the linked list
Three ways to start WPF project
Wechat applet coordinate location interface usage (II) map interface
[JVM series 4] common JVM commands
Binary tree initialization code
Code d'initialisation de l'arbre binaire
Redis server configuration
Wechat applet switch style rewriting
2022.05.29
2022.05.29