绑定组件

关于设置Dapr绑定组件的指南

Dapr integrates with external resources to allow apps to both be triggered by external events and interact with the resources. Each binding component has a name and this name is used when interacting with the resource.

As with other building block components, binding components are extensible and can be found in the components-contrib repo.

A binding in Dapr is described using a Component file with the following fields:

  1. apiVersion: dapr.io/v1alpha1
  2. kind: Component
  3. metadata:
  4. name: <NAME>
  5. namespace: <NAMESPACE>
  6. spec:
  7. type: bindings.<NAME>
  8. version: v1
  9. metadata:
  10. - name: <KEY>
  11. value: <VALUE>
  12. - name: <KEY>
  13. value: <VALUE>
  14. ...

The type of binding is determined by the type field, and things like connection strings and other metadata are put in the .metadata section.

Different supported bindings will have different specific fields that would need to be configured. For example, when configuring a binding for Azure Blob Storage, the file would look like this:

  1. apiVersion: dapr.io/v1alpha1
  2. kind: Component
  3. metadata:
  4. name: <NAME>
  5. namespace: <NAMESPACE>
  6. spec:
  7. type: bindings.azure.blobstorage
  8. version: v1
  9. metadata:
  10. - name: storageAccount
  11. value: myStorageAccountName
  12. - name: storageAccessKey
  13. value: ***********
  14. - name: container
  15. value: container1
  16. - name: decodeBase64
  17. value: <bool>
  18. - name: getBlobRetryCount
  19. value: <integer>

应用配置

一旦您创建了组件的 YAML 文件,按照以下说明来根据您的主机环境应用它:

要在本地运行,创建一个包含YAML文件的components目录,并提供dapr run命令的路径,标志为--components-path

若要在 Kubernetes 中部署,假定您的组件文件名为 mybinding.yaml,运行:

  1. kubectl apply -f mybinding.yaml

Supported bindings

Visit the bindings reference for a full list of supported resources.

相关链接