当前位置:网站首页>Teach you to learn dapr - 8 binding
Teach you to learn dapr - 8 binding
2022-06-26 16:46:00 【Masa technical team】
Catalog
Hands teach you how to Dapr - 1. .Net The era of developers
Hands teach you how to Dapr - 2. Must know the concept of
Hands teach you how to Dapr - 3. Use Dapr Run the first .Net Program
Hands teach you how to Dapr - 4. The service call
Hands teach you how to Dapr - 5. State management
Hands teach you how to Dapr - 6. Publish subscribe
Hands teach you how to Dapr - 7. Actors
Hands teach you how to Dapr - 8. binding
Introduce
Use bindings , You can use events from external systems to trigger your application , Or interact with external systems . This building block provides several benefits for you and your code :
- Eliminate connection and polling message systems ( Such as queues and message buses ) Complexity
- Focus on business logic , Rather than the implementation details of how to interact with the system
- Protect your code from SDK Or the impact of the library
- Handle retry and failback
- The runtime switches between bindings
- Building portable applications , Environment specific bindings are set , No need to change the code
Input binding
The input binding is used to trigger your application when an event from an external resource occurs . Optional payload and Metadata Can be sent with the request .
To receive events from the input binding :
- Define and describe binding types and their metadata ( Connection information, etc ) The components of YAML
- Listen for incoming events HTTP Endpoint , Or use gRPC proto Library to get incoming events
Output binding
The output binding allows you to invoke external resources . Optional payload and Metadata Can be sent with the request .
To invoke the output binding :
- Define and describe binding types and their metadata ( Connection information, etc ) The components of YAML
- Use HTTP or gRPC Method calls have optional
payloadThe binding of
Use scenarios
Use bindings , Your code can be triggered by incoming events from different resources , These resources can be anything : queue 、 Messaging pipeline 、 The cloud service 、 File system, etc .
This is important for event driven processing 、 A data pipeline or just a general response to events and further processing is ideal .
Dapr Binding allows you to :
- Does not contain specific SDK Or library
- Replace the binding without changing the code
- Focus on business logic rather than event resource implementation
at present Dapr Cross is not yet supported Dapr Mutual call , and
yaronOne of the solutions given is binding
Currently, binding supports 40 Middle component , Include Aliyun、Azure、AWS And other cloud service vendors , It also includes common such as Cron, kafka, MQTT, SMTP, Redis As well as a variety of MQ etc. .
The picture below is .Net Dapr An example in the official tutorial

Configuration components
This article will use rabbitmq To demonstrate ( Why not redis, because redis Rollover , Only support output, I didn't notice supported), As mentioned in previous articles , First configure yaml
install
rabbitmqdocker pull rabbitmq:3.8.25-managementfunction
rabbitmqdocker run -d --hostname rabbitMQ --name my-rabbitMQ -p 15672:15672 -p 5672:5672 -e RABBITMQ_DEFAULT_USER=admin -e RABBITMQ_DEFAULT_PASS=admin rabbitmq:3.8.25-managementWindows Open Directory
%USERPROFILE%\.dapr\components, establishbinding.yaml, The contents are as followsapiVersion: dapr.io/v1alpha1kind: Componentmetadata: name: myevent namespace: defaultspec: type: bindings.rabbitmq version: v1 metadata: - name: queueName value: queue1 - name: host value: amqp://admin:[email protected]:5672 - name: durable value: true - name: deleteWhenUnused value: false - name: ttlInSeconds value: 60 - name: prefetchCount value: 0 - name: exclusive value: false - name: maxPriority value: 5Open the browser , Input url:
http://localhost:15672/, The account password is admin, see rabbitmq It's working properly
.Net call Dapr The binding of
establish Assignment.Server
establish Class library project , And add Dapr.Actors.AspNetCoreNuGet Package references and Assignment.Shared Project reference , Finally, modify the program port to 5000.
modify program.cs
var builder = WebApplication.CreateBuilder(args);var app = builder.Build();app.MapPost("/myevent", ([Microsoft.AspNetCore.Mvc.FromBody] string word) => Console.WriteLine($"Hello {word}!"));app.Run(); notes : Be sure to use POST Method, Remember the parameters in Body Inside . Default Url And bindings Of name Corresponding . Can you change the route ? Of course I can , See the configuration below
spec: type: binding.rabbitmq metadata: - name: route value: /oneventfunction Assignment.Server
Use Dapr CLI To start up , First use the command line tool to jump to the directory dapr-study-room\Assignment07\Assignment.Server, Then execute the following command
dapr run --app-id testbinding --app-port 5000 --dapr-http-port 3500 --dapr-grpc-port 50001 dotnet runVerify whether the server binding configuration is successful
Open the browser , Input url:http://localhost:15672/#/queues, The account password is admin, Check to see if you have created a file named queue1 Queues , As shown in the figure below :

establish Assignment.Client
establish Console project , And add Dapr.ActorsNuGet Package references and Assignment.Shared Project reference .
modify Program.cs
using Dapr.Client;var client = new DaprClientBuilder().Build();await client.InvokeBindingAsync("myevent", "create", "World");Console.WriteLine("Binding sent.");function Assignment.Client
Use Dapr CLI To start up , First use the command line tool to jump to the directory dapr-study-room\Assignment07\Assignment.Client, Then execute the following command
dotnet runSource code of this chapter
Assignment08
https://github.com/doddgu/dapr-study-room
We are acting , New framework 、 New ecology
Our goal is The freedom of the 、 Easy-to-use 、 Highly malleable 、 functional 、 Robust .
So we learn from Building blocks Design concept of , Working on a new framework MASA Framework, What are its characteristics ?
- Native support Dapr, And allow Dapr Replace with traditional means of communication
- Unlimited architecture , Single application 、SOA、 Micro services support
- Support .Net Native framework , Reduce the burden of learning , In addition to the concepts that must be introduced in a specific field , Insist on not making new wheels
- Rich ecological support , In addition to the framework, there are component libraries 、 Authority Center 、 Configuration center 、 Troubleshooting center 、 A series of products such as Alarm Center
- Unit test coverage of the core code base 90%+
- Open source 、 free 、 Community driven
- What is the ? We are waiting for you , Come together and discuss
After several months of production project practice , Completed POC, At present, the previous accumulation is being refactored into new open source projects
At present, the source code has been synchronized to Github( The document site is under planning , Will gradually improve ):
QQ Group :7424099
Wechat group : Plus technology operation wechat (MasaStackTechOps), Remarks , Invite in

边栏推荐
- 【小5聊】毕业8年,一直在追梦的路上
- Develop operator based on kubebuilder (for getting started)
- How to implement interface current limiting?
- 国内首款开源 MySQL HTAP 数据库即将发布,三大看点提前告知
- Gui+sqlserver examination system
- Summary of all knowledge points of C language
- Science | 红树林中发现的巨型细菌挑战传统无核膜观念
- Exquisite makeup has become the "soft power" of camping, and the sales of vipshop outdoor beauty and skin care products have surged
- 无需人工先验!港大&同济&LunarAI&旷视提出基于语义分组的自监督视觉表征学习,显著提升目标检测、实例分割和语义分割任务!...
- [207] several possible causes of Apache crash
猜你喜欢

pybullet机器人仿真环境搭建 5.机器人位姿可视化

无需人工先验!港大&同济&LunarAI&旷视提出基于语义分组的自监督视觉表征学习,显著提升目标检测、实例分割和语义分割任务!...

TCP congestion control details | 1 summary

Arduino UNO + DS1302简单获取时间并串口打印

Summary of all knowledge points of C language

No manual prior is required! HKU & Tongji & lunarai & Kuangshi proposed self supervised visual representation learning based on semantic grouping, which significantly improved the tasks of target dete

Qt 5.9.8 安装教程

MS | Xie Liwei group found that mixed probiotics and their metabolites could alleviate colitis

【力扣刷题】11.盛最多水的容器//42.接雨水

Développer un opérateur basé sur kubebuilder (démarrer)
随机推荐
Arduino UNO + DS1302简单获取时间并串口打印
Scala Foundation (2): variables et types de données
Exquisite makeup has become the "soft power" of camping, and the sales of vipshop outdoor beauty and skin care products have surged
Niuke programming problem -- dynamic programming of must brush 101 (a thorough understanding of dynamic programming)
TCP拥塞控制详解 | 1. 概述
Toupper function
长安链交易防重之布谷鸟过滤器
proxy
JS tutorial - printing stickers / labels using the electronjs desktop application
【力扣刷题】11.盛最多水的容器//42.接雨水
Scala 基礎 (二):變量和數據類型
[机缘参悟-31]:鬼谷子-抵巇[xī]篇-危机是危险与机会并存
C语言 头哥习题答案截图
[Li Kou brush questions] 11 Container holding the most water //42 Rain water connection
Redis migration (recommended operation process) 1
TCP congestion control details | 1 summary
Summary of all knowledge points of C language
Least squares system identification class II: recursive least squares
R329 (maix-ii-a (M2A) data summary
数据分析----numpy快速入门