当前位置:网站首页>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

边栏推荐
- 内存分区模型
- C language --- basic function realization of push box 01
- Redis migration (recommended operation process)
- 最小二乘系统辨识课 中篇:递归最小二乘
- 100+ data science interview questions and answers Summary - basic knowledge and data analysis
- 进军AR领域,这一次罗永浩能成吗?
- Hyperf框架使用阿里云OSS上传失败
- When a programmer is disturbed 10 times a day, the consequences are amazing!
- 数据分析----numpy快速入门
- [chat in 5] eight years after graduation, I have been pursuing my dream
猜你喜欢
![[from database deletion to running] JDBC conclusion (finish the series in one day!! run as soon as you finish learning!)](/img/75/2fb1a4e6215e404df34849e9e4f21a.png)
[from database deletion to running] JDBC conclusion (finish the series in one day!! run as soon as you finish learning!)

MS|谢黎炜组发现混合益生菌制剂及其代谢产物可缓解结肠炎

内存分区模型

了解下常见的函数式接口

QT 5.9.8 installation tutorial

Science | 红树林中发现的巨型细菌挑战传统无核膜观念

C语言所有知识点小结

我把它当副业月入3万多,新手月入过万的干货分享!

r329(MAIX-II-A(M2A)资料汇总

1-12vmware adds SSH function
随机推荐
LeetCode Algorithm 24. Exchange the nodes in the linked list in pairs
What is flush software? Is it safe to open an account online?
num[i]++
无需人工先验!港大&同济&LunarAI&旷视提出基于语义分组的自监督视觉表征学习,显著提升目标检测、实例分割和语义分割任务!...
redis的二进制数组命令
[机缘参悟-31]:鬼谷子-抵巇[xī]篇-危机是危险与机会并存
Redis Guide (8): principle and implementation of Qianfan Jingfa distributed lock
Développer un opérateur basé sur kubebuilder (démarrer)
JS教程之使用 ElectronJS、VueJS、SQLite 和 Sequelize ORM 从 A 到 Z 创建多对多 CRUD 应用程序
Redis migration (recommended operation process)
【从删库到跑路】MySQL基础 完结篇(入个门先跑路了。。)
【MATLAB项目实战】基于卷积神经网络与双向长短时(CNN-LSTM)融合的锂离子电池剩余使用寿命预测
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
安信证券排名第几位?开户安全吗?
100+数据科学面试问题和答案总结 - 基础知识和数据分析
C language -- legal identifier and integer
请指教同花顺软件究竟是什么?网上开户是否安全么?
Cuckoo filter for Chang'an chain transaction
Knowing these commands allows you to master shell's own tools
108. 简易聊天室11:实现客户端群聊