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

边栏推荐
- 5G未平6G再启,中国引领无线通信,6G的最大优势在哪里?
- JS教程之 使用 Electron.JS 构建原生桌面应用程序乒乓游戏
- 108. 简易聊天室11:实现客户端群聊
- C语言 头哥习题答案截图
- Vibrating liquid quantity detecting device
- [Li Kou brush questions] 11 Container holding the most water //42 Rain water connection
- redis的二进制数组命令
- stm32h7b0替代h750程序导致单片机挂掉无法烧录程序问题
- GUI+SQLServer考试系统
- 网页课程设计大作业——华山旅游网
猜你喜欢

心情不好,我就这样写代码

内存分区模型

构造函数和析构函数

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

探讨:下一代稳定币

Set up your own website (16)

长安链交易防重之布谷鸟过滤器

Dialogue with the senior management of Chang'an Mazda, new products will be released in Q4, and space and intelligence will lead the Japanese system

JS教程之使用 ElectronJS、VueJS、SQLite 和 Sequelize ORM 从 A 到 Z 创建多对多 CRUD 应用程序

Natural language inference with attention and fine tuning Bert pytorch
随机推荐
[understanding of opportunity -31]: Guiguzi - Daoyu [x ī] Crisis is the coexistence of danger and opportunity
用Attention和微调BERT进行自然语言推断-PyTorch
JS教程之使用 ElectronJS 桌面应用程序打印贴纸/标签
[Li Kou brush questions] 11 Container holding the most water //42 Rain water connection
MS|谢黎炜组发现混合益生菌制剂及其代谢产物可缓解结肠炎
Which position does Anxin securities rank? Is it safe to open an account?
[chat in 5] eight years after graduation, I have been pursuing my dream
How to implement interface current limiting?
最小二乘系统辨识课 中篇:递归最小二乘
[force deduction question] two point search: 4 Find the median of two positive arrays
Overall context of concurrent programming
Greenplum数据库故障分析——semop(id=2000421076,num=11) failed: invalid argument
精致妆容成露营“软实力”,唯品会户外美妆护肤产品销量激增
108. 简易聊天室11:实现客户端群聊
【从删库到跑路】JDBC 完结篇(一天学完系列!!学完赶紧跑!)
[from deleting the database to running] the end of MySQL Foundation (the first step is to run.)
Redis migration (recommended operation process) 1
I regard it as a dry product with a monthly income of more than 30000 yuan for sidelines and more than 10000 yuan for novices!
C语言 头哥习题答案截图
网页课程设计大作业——华山旅游网