实例介绍
本示例应用模拟了一个交通控制系统,通过在高速公路的起点和终点设置摄像头来测量车辆的平均速度,并在超速时向车主发送罚单。该系统包含几个服务:车辆注册服务、罚款收集服务、交通控制服务和摄像头模拟器。
此外,本文还详细介绍了如何在自托管环境或Kubernetes上运行这个应用,以及如何使用Dapr的各种构建块和组件来实现应用的不同方面,例如服务调用、事件发布与订阅、状态管理和秘密管理等。
public class TrafficControlService { public void EntryCamera(string licenseNumber, DateTime timestamp) { // 处理车辆进入 } public void ExitCamera(string licenseNumber, DateTime timestamp) { // 处理车辆离开并计算平均速度 } }
【实例截图】
【核心代码】
文件清单
└── dapr-traffic-control-6129bf26265aa650c269d1b94a21f76f88bc7446
├── dapr-trafficcontrol-sample-diagrams.drawio
├── Figures.pptx
├── img
│ ├── dapr-for-net-devs-cover-thumb.png
│ ├── dapr-setup.png
│ ├── logging-finecollectionservice.png
│ ├── logging-simulation.png
│ ├── logging-trafficcontrolservice-actors.png
│ ├── logging-trafficcontrolservice.png
│ ├── logging-vehicleregistrationservice.png
│ ├── mailbox.png
│ ├── redis-password.png
│ ├── sequence-dapr.png
│ ├── sequence.png
│ ├── services.png
│ ├── speed-trap-overview.png
│ └── visualsim.png
├── LICENSE
├── README.md
└── src
├── dapr
│ ├── components
│ │ ├── email.yaml
│ │ ├── entrycam.yaml
│ │ ├── exitcam.yaml
│ │ ├── pubsub.yaml
│ │ ├── secrets-file.yaml
│ │ ├── secrets.json
│ │ └── statestore.yaml
│ └── config
│ ├── config.yaml
│ ├── consul-config.yaml
│ └── ratelimit-config.yaml
├── DaprTrafficControl.code-workspace
├── FineCollectionService
│ ├── appsettings.Development.json
│ ├── appsettings.json
│ ├── Controllers
│ │ └── CollectionController.cs
│ ├── Dockerfile
│ ├── DomainServices
│ │ ├── HardCodedFineCalculator.cs
│ │ └── IFineCalculator.cs
│ ├── FineCollectionService.csproj
│ ├── GlobalUsings.cs
│ ├── Helpers
│ │ └── EmailUtils.cs
│ ├── Models
│ │ ├── SpeedingViolation.cs
│ │ └── VehicleInfo.cs
│ ├── Program.cs
│ ├── Properties
│ │ └── launchSettings.json
│ ├── Proxies
│ │ └── VehicleRegistrationService.cs
│ ├── start-selfhosted.ps1
│ ├── start-selfhosted.sh
│ └── test.http
├── global.json
├── Infrastructure
│ ├── consul
│ │ ├── start-consul.ps1
│ │ ├── start-consul.sh
│ │ ├── stop-consul.ps1
│ │ └── stop-consul.sh
│ ├── maildev
│ │ ├── start-maildev.ps1
│ │ ├── start-maildev.sh
│ │ ├── stop-maildev.ps1
│ │ └── stop-maildev.sh
│ ├── mosquitto
│ │ ├── Dockerfile
│ │ ├── mosquitto.conf
│ │ ├── start-mosquitto.ps1
│ │ ├── start-mosquitto.sh
│ │ ├── stop-mosquitto.ps1
│ │ └── stop-mosquitto.sh
│ ├── rabbitmq
│ │ ├── start-rabbitmq.ps1
│ │ ├── start-rabbitmq.sh
│ │ ├── stop-rabbitmq.ps1
│ │ └── stop-rabbitmq.sh
│ ├── start-all.ps1
│ ├── start-all.sh
│ ├── stop-all.ps1
│ └── stop-all.sh
├── k8s
│ ├── build-docker-images.ps1
│ ├── dapr-config.yaml
│ ├── email.yaml
│ ├── entrycam.yaml
│ ├── exitcam.yaml
│ ├── finecollectionservice.yaml
│ ├── maildev.yaml
│ ├── mosquitto
│ │ ├── Dockerfile
│ │ └── mosquitto.conf
│ ├── mosquitto.yaml
│ ├── namespace.yaml
│ ├── pubsub-rabbitmq.yaml
│ ├── rabbitmq.yaml
│ ├── redis.yaml
│ ├── secrets.yaml
│ ├── simulation.yaml
│ ├── start.ps1
│ ├── state-redis.yaml
│ ├── stop.ps1
│ ├── trafficcontrolservice.yaml
│ ├── vehicleregistrationservice.yaml
│ └── zipkin.yaml
├── Observability
│ └── grafana
│ ├── get-grafana-password.ps1
│ ├── grafana-actor-dashboard.json
│ ├── grafana-sidecar-dashboard.json
│ ├── grafana-system-services-dashboard.json
│ ├── install-grafana.ps1
│ ├── namespace.yaml
│ ├── start-grafana.ps1
│ └── uninstall-grafana.ps1
├── Simulation
│ ├── CameraSimulation.cs
│ ├── Dockerfile
│ ├── Events
│ │ └── VehicleRegistered.cs
│ ├── GlobalUsings.cs
│ ├── Program.cs
│ ├── Proxies
│ │ ├── ITrafficControlService.cs
│ │ └── MqttTrafficControlService.cs
│ └── Simulation.csproj
├── TrafficControlService
│ ├── Actors
│ │ ├── IVehicleActor.cs
│ │ └── VehicleActor.cs
│ ├── appsettings.Development.json
│ ├── appsettings.json
│ ├── Controllers
│ │ └── TrafficController.cs
│ ├── Dockerfile
│ ├── DomainServices
│ │ ├── DefaultSpeedingViolationCalculator.cs
│ │ └── ISpeedingViolationCalculator.cs
│ ├── Events
│ │ └── VehicleRegistered.cs
│ ├── GlobalUsings.cs
│ ├── Models
│ │ ├── SpeedingViolation.cs
│ │ └── VehicleState.cs
│ ├── Program.cs
│ ├── Properties
│ │ └── launchSettings.json
│ ├── Repositories
│ │ ├── DaprVehicleStateRepository.cs
│ │ └── IVehicleStateRepository.cs
│ ├── start-selfhosted.ps1
│ ├── start-selfhosted.sh
│ ├── test.http
│ └── TrafficControlService.csproj
├── VehicleRegistrationService
│ ├── apply-load.ps1
│ ├── apply-load.sh
│ ├── appsettings.Development.json
│ ├── appsettings.json
│ ├── Controllers
│ │ └── VehicleInfoController.cs
│ ├── Dockerfile
│ ├── GlobalUsings.cs
│ ├── Models
│ │ └── VehicleInfo.cs
│ ├── Program.cs
│ ├── Properties
│ │ └── launchSettings.json
│ ├── Repositories
│ │ ├── InMemoryVehicleInfoRepository.cs
│ │ └── IVehicleRepository.cs
│ ├── start-selfhosted.ps1
│ ├── start-selfhosted.sh
│ ├── test.http
│ └── VehicleRegistrationService.csproj
└── VisualSimulation
├── appsettings.Development.json
├── appsettings.json
├── GlobalUsings.cs
├── Program.cs
├── Properties
│ └── launchSettings.json
├── VisualSimulation.csproj
└── wwwroot
├── assets
│ ├── ambulance.png
│ ├── background.png
│ ├── brushes.png
│ ├── camera.png
│ ├── clouds.png
│ ├── crossover.png
│ ├── garbage.png
│ ├── hummer.png
│ ├── mini.png
│ ├── minivan.png
│ ├── paint-general.png
│ ├── pickup.png
│ ├── road-bottom.png
│ ├── road-middle.png
│ ├── schoolbus.png
│ ├── sedan.png
│ ├── semitruck.png
│ ├── structure-overhead.png
│ ├── structure-pole.png
│ └── truck.png
├── favicon.ico
├── index.html
└── js
├── car.js
├── car-painter.js
├── debugscene.js
├── lane.js
├── main.js
├── merge-aggressive.js
├── merge.js
├── mqttws31.min.js
├── phaser.min.js
├── settings.js
├── trafficcontrolsvc-http.js
├── trafficcontrolsvc-mqtt.js
├── trafficscene.js
└── utils.js
43 directories, 185 files
标签:
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论