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

边栏推荐
- 建立自己的网站(16)
- Scala 基础 (二):变量和数据类型
- Overall context of concurrent programming
- Arduino UNO + DS1302简单获取时间并串口打印
- The first open source MySQL HTAP database in China will be released soon, and the three highlights will be notified in advance
- 安信证券排名第几位?开户安全吗?
- Redis 概述整理
- 进军AR领域,这一次罗永浩能成吗?
- Acid of redis
- Fgetc() reads content from file
猜你喜欢

TCP拥塞控制详解 | 1. 概述

精致妆容成露营“软实力”,唯品会户外美妆护肤产品销量激增

1-12Vmware新增SSH功能

C语言 头哥习题答案截图

Junit单元测试
![[机缘参悟-31]:鬼谷子-抵巇[xī]篇-危机是危险与机会并存](/img/e8/9c5f1658a252c3c80503b5021917f6.jpg)
[机缘参悟-31]:鬼谷子-抵巇[xī]篇-危机是危险与机会并存

对话长安马自达高层,全新产品将在Q4发布,空间与智能领跑日系

JUnit unit test

TCP congestion control details | 1 summary

Kubecon China 2021 Alibaba cloud special session is coming! These first day highlights should not be missed
随机推荐
R329 (maix-ii-a (M2A) data summary
Natural language inference with attention and fine tuning Bert pytorch
Experience in hierarchical debugging of boards and cards
建立自己的网站(16)
Redis migration (recommended operation process) 1
C language --- basic function realization of push box 01
Redis 迁移(操作流程建议)1
JUnit unit test
Niuke programming problem -- dynamic programming of must brush 101 (a thorough understanding of dynamic programming)
[learn FPGA programming from scratch -46]: Vision - development and technological progress of integrated circuits
Redis order sorting command
Acid of redis
MS | Xie Liwei group found that mixed probiotics and their metabolites could alleviate colitis
《软件工程》期末重点复习笔记
[matlab project practice] prediction of remaining service life of lithium ion battery based on convolutional neural network and bidirectional long short time (cnn-lstm) fusion
Scala Basics (II): variables and data types
基于Kubebuilder开发Operator(入门使用)
C语言 头哥习题答案截图
构造函数和析构函数
STM32F103C8T6实现呼吸灯代码