mirror of https://github.com/dapr/docs.git
Merge branch 'bindings_quickstarts' of https://github.com/nirmash/docs into bindings_quickstarts
This commit is contained in:
commit
33ff42dbe3
|
@ -6,49 +6,56 @@ weight: 100
|
|||
description: Overview of the bindings API building block
|
||||
---
|
||||
|
||||
## Introduction
|
||||
Using Dapr's bindings API, you can both trigger your app with events coming in from external systems and interface with external systems. In addition, the Dapr binding API enables you to:
|
||||
|
||||
Using bindings, you can trigger your app with events coming in from external systems, or interface with external systems. This building block provides several benefits for you and your code:
|
||||
|
||||
- Remove the complexities of connecting to, and polling from, messaging systems such as queues and message buses
|
||||
- Focus on business logic and not implementation details of how to interact with a system
|
||||
- Remove the complexities of connecting to and polling from messaging systems, such as queues and message buses
|
||||
- Focus on business logic, instead of the implementation details of how to interact with a system
|
||||
- Keep your code free from SDKs or libraries
|
||||
- Handle retries and failure recovery
|
||||
- Switch between bindings at run time
|
||||
- Build portable applications where environment-specific bindings are set-up and no code changes are required
|
||||
- Build portable applications with environment-specific bindings set up and no code changes required
|
||||
|
||||
For a specific example, bindings would allow your microservice to respond to incoming Twilio/SMS messages without adding or configuring a third-party Twilio SDK, worrying about polling from Twilio (or using websockets, etc.).
|
||||
For example, with bindings, your microservice can respond to incoming Twilio/SMS messages without:
|
||||
|
||||
Bindings are developed independently of Dapr runtime. You can view and contribute to the bindings [here](https://github.com/dapr/components-contrib/tree/master/bindings).
|
||||
- Adding or configuring a third-party Twilio SDK
|
||||
- Worrying about polling from Twilio (or using websockets, etc.)
|
||||
|
||||
{{% alert title="Note" color="primary" %}}
|
||||
Bindings are developed independently of Dapr runtime. You can [view and contribute to the bindings](https://github.com/dapr/components-contrib/tree/master/bindings).
|
||||
|
||||
{{% /alert %}}
|
||||
|
||||
## Input bindings
|
||||
|
||||
Input bindings are used to trigger your application when an event from an external resource has occurred.
|
||||
An optional payload and metadata may be sent with the request.
|
||||
With input bindings, you can trigger your application when an event from an external resource has occurred. An optional payload and metadata may be sent with the request.
|
||||
|
||||
In order to receive events from an input binding:
|
||||
|
||||
1. Define the component YAML that describes the type of binding and its metadata (connection info, etc.)
|
||||
2. Listen on an HTTP endpoint for the incoming event, or use the gRPC proto library to get incoming events
|
||||
1. Define the component YAML that describes the type of binding and its metadata (connection info, etc.).
|
||||
2. Listen on an HTTP endpoint for the incoming event, or use the gRPC proto library to get incoming events.
|
||||
|
||||
> On startup Dapr sends a `OPTIONS` request for all defined input bindings to the application and expects a status code other than `NOT FOUND (404)` if this application wants to subscribe to the binding.
|
||||
{{% alert title="Note" color="primary" %}}
|
||||
On startup, Dapr sends [an OPTIONS request]({{< ref "bindings_api.md#invoking-service-code-through-input-bindings" >}}) for all defined input bindings to the application and expects a status code 2xx or 405 if this application wants to subscribe to the binding.
|
||||
|
||||
{{% /alert %}}
|
||||
|
||||
Read the [Create an event-driven app using input bindings]({{< ref howto-triggers.md >}}) page to get started with input bindings.
|
||||
|
||||
## Output bindings
|
||||
|
||||
Output bindings allow you to invoke external resources. An optional payload and metadata can be sent with the invocation request.
|
||||
With output bindings, you can invoke external resources. An optional payload and metadata can be sent with the invocation request.
|
||||
|
||||
In order to invoke an output binding:
|
||||
|
||||
1. Define the component YAML that describes the type of binding and its metadata (connection info, etc.)
|
||||
2. Use the HTTP endpoint or gRPC method to invoke the binding with an optional payload
|
||||
1. Define the component YAML that describes the type of binding and its metadata (connection info, etc.).
|
||||
2. Use the HTTP endpoint or gRPC method to invoke the binding with an optional payload.
|
||||
|
||||
Read the [Use output bindings to interface with external resources]({{< ref howto-bindings.md >}}) page to get started with output bindings.
|
||||
|
||||
## Next Steps
|
||||
* Follow these guides on:
|
||||
* [How-To: Trigger a service from different resources with input bindings]({{< ref howto-triggers.md >}})
|
||||
* [How-To: Use output bindings to interface with external resources]({{< ref howto-bindings.md >}})
|
||||
* Try out the [bindings quickstart](https://github.com/dapr/quickstarts/tree/master/tutorials/bindings/README.md) which shows how to bind to a Kafka queue
|
||||
* Read the [bindings API specification]({{< ref bindings_api.md >}})
|
||||
|
||||
- Follow these guides on:
|
||||
- [How-To: Trigger a service from different resources with input bindings]({{< ref howto-triggers.md >}})
|
||||
- [How-To: Use output bindings to interface with external resources]({{< ref howto-bindings.md >}})
|
||||
- Try out the [bindings tutorial](https://github.com/dapr/quickstarts/tree/master/tutorials/bindings/README.md) to experiment with binding to a Kafka queue.
|
||||
- Read the [bindings API specification]({{< ref bindings_api.md >}})
|
||||
|
|
|
@ -212,7 +212,40 @@ message SubscribeConfigurationRequest {
|
|||
}
|
||||
```
|
||||
|
||||
Using this method, you can subscribe to changes in specific keys for a given configuration store. gRPC streaming varies widely based on language. [See the gRPC examples](https://grpc.io/docs/languages/) for usage.
|
||||
Using this method, you can subscribe to changes in specific keys for a given configuration store. gRPC streaming varies widely based on language - see the [gRPC examples here](https://grpc.io/docs/languages/) for usage.
|
||||
|
||||
Below are the examples in sdks:
|
||||
|
||||
{{< tabs Python>}}
|
||||
|
||||
{{% codetab %}}
|
||||
```python
|
||||
#dependencies
|
||||
import asyncio
|
||||
from dapr.clients import DaprClient
|
||||
#code
|
||||
async def executeConfiguration():
|
||||
with DaprClient() as d:
|
||||
CONFIG_STORE_NAME = 'configstore'
|
||||
key = 'orderId'
|
||||
# Subscribe to configuration by key.
|
||||
configuration = await d.subscribe_configuration(store_name=CONFIG_STORE_NAME, keys=[key], config_metadata={})
|
||||
if configuration != None:
|
||||
items = configuration.get_items()
|
||||
for item in items:
|
||||
print(f"Subscribe key={item.key} value={item.value} version={item.version}", flush=True)
|
||||
else:
|
||||
print("Nothing yet")
|
||||
asyncio.run(executeConfiguration())
|
||||
```
|
||||
|
||||
```bash
|
||||
dapr run --app-id orderprocessing --components-path components/ -- python3 OrderProcessingService.py
|
||||
```
|
||||
|
||||
{{% /codetab %}}
|
||||
|
||||
{{< /tabs >}}
|
||||
|
||||
#### Stop watching configuration items
|
||||
|
||||
|
|
|
@ -191,15 +191,25 @@ The programmatic approach returns the `routes` JSON structure within the code, u
|
|||
{{% codetab %}}
|
||||
|
||||
```csharp
|
||||
[Topic("pubsub", "checkout", event.type ==\"order\"")]
|
||||
[HttpPost("orders")]
|
||||
public async Task<ActionResult<Stock>> HandleCheckout(Checkout checkout, [FromServices] DaprClient daprClient)
|
||||
[Topic("pubsub", "orders")]
|
||||
[HttpPost("/checkout")]
|
||||
public async Task<ActionResult<Order>>Checkout(Order order, [FromServices] DaprClient daprClient)
|
||||
{
|
||||
// Logic
|
||||
return stock;
|
||||
return order;
|
||||
}
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```csharp
|
||||
// Dapr subscription in [Topic] routes orders topic to this route
|
||||
app.MapPost("/checkout", [Topic("pubsub", "orders")] (Order order) => {
|
||||
Console.WriteLine("Subscriber received : " + order);
|
||||
return Results.Ok(order);
|
||||
});
|
||||
```
|
||||
|
||||
{{% /codetab %}}
|
||||
|
||||
{{% codetab %}}
|
||||
|
|
|
@ -508,7 +508,7 @@ For this example, you will need:
|
|||
- [Dapr CLI and initialized environment](https://docs.dapr.io/getting-started).
|
||||
- Java JDK 11 (or greater):
|
||||
- [Oracle JDK](https://www.oracle.com/technetwork/java/javase/downloads/index.html#JDK11), or
|
||||
- [OpenJDK](https://jdk.java.net/13/)
|
||||
- [OpenJDK](https://jdk.java.net/projects/jdk/13/)
|
||||
- [Apache Maven](https://maven.apache.org/install.html), version 3.x.
|
||||
<!-- IGNORE_LINKS -->
|
||||
- [Docker Desktop](https://www.docker.com/products/docker-desktop)
|
||||
|
|
|
@ -352,7 +352,7 @@ For this example, you will need:
|
|||
- [Dapr CLI and initialized environment](https://docs.dapr.io/getting-started).
|
||||
- Java JDK 11 (or greater):
|
||||
- [Oracle JDK](https://www.oracle.com/technetwork/java/javase/downloads/index.html#JDK11), or
|
||||
- [OpenJDK](https://jdk.java.net/13/)
|
||||
- [OpenJDK](https://jdk.java.net/projects/jdk/13/)
|
||||
- [Apache Maven](https://maven.apache.org/install.html), version 3.x.
|
||||
<!-- IGNORE_LINKS -->
|
||||
- [Docker Desktop](https://www.docker.com/products/docker-desktop)
|
||||
|
|
|
@ -388,7 +388,7 @@ For this example, you will need:
|
|||
- [Dapr CLI and initialized environment](https://docs.dapr.io/getting-started).
|
||||
- Java JDK 11 (or greater):
|
||||
- [Oracle JDK](https://www.oracle.com/technetwork/java/javase/downloads/index.html#JDK11), or
|
||||
- [OpenJDK](https://jdk.java.net/13/)
|
||||
- [OpenJDK](https://jdk.java.net/projects/jdk/13/)
|
||||
- [Apache Maven](https://maven.apache.org/install.html), version 3.x.
|
||||
<!-- IGNORE_LINKS -->
|
||||
- [Docker Desktop](https://www.docker.com/products/docker-desktop)
|
||||
|
|
|
@ -386,7 +386,7 @@ For this example, you will need:
|
|||
- [Dapr CLI and initialized environment](https://docs.dapr.io/getting-started).
|
||||
- Java JDK 11 (or greater):
|
||||
- [Oracle JDK](https://www.oracle.com/technetwork/java/javase/downloads/index.html#JDK11), or
|
||||
- [OpenJDK](https://jdk.java.net/13/)
|
||||
- [OpenJDK](https://jdk.java.net/projects/jdk/13/)
|
||||
- [Apache Maven](https://maven.apache.org/install.html), version 3.x.
|
||||
<!-- IGNORE_LINKS -->
|
||||
- [Docker Desktop](https://www.docker.com/products/docker-desktop)
|
||||
|
|
|
@ -99,7 +99,7 @@ OPTIONS http://localhost:<appPort>/<name>
|
|||
Code | Description
|
||||
---- | -----------
|
||||
404 | Application does not want to bind to the binding
|
||||
all others | Application wants to bind to the binding
|
||||
2xx or 405 | Application wants to bind to the binding
|
||||
|
||||
#### URL Parameters
|
||||
|
||||
|
|
|
@ -190,7 +190,7 @@ First, download the code of the stored procedures for the version of Dapr that y
|
|||
|
||||
```sh
|
||||
# Set this to the version of Dapr that you're using
|
||||
DAPR_VERSION="v1.7.0"
|
||||
DAPR_VERSION="release-{{% dapr-latest-version short="true" %}}"
|
||||
curl -LfO "https://raw.githubusercontent.com/dapr/components-contrib/${DAPR_VERSION}/state/azure/cosmosdb/storedprocedures/__daprver__.js"
|
||||
curl -LfO "https://raw.githubusercontent.com/dapr/components-contrib/${DAPR_VERSION}/state/azure/cosmosdb/storedprocedures/__dapr_v2__.js"
|
||||
```
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
<p>Table captions:</p>
|
||||
<blockquote>
|
||||
<p><code>Status</code>: <a href="http://localhost:1313/operations/components/certification-lifecycle/">Component
|
||||
<p><code>Status</code>: <a href="/operations/components/certification-lifecycle/">Component
|
||||
certification</a> status</p>
|
||||
</blockquote>
|
||||
<ul>
|
||||
<li><a href="http://localhost:1313/operations/components/certification-lifecycle/#alpha">Alpha</a></li>
|
||||
<li><a href="http://localhost:1313/operations/components/certification-lifecycle/#beta">Beta</a></li>
|
||||
<li><a href="http://localhost:1313/operations/components/certification-lifecycle/#stable">Stable</a></li>
|
||||
<li><a href="/operations/components/certification-lifecycle/#alpha">Alpha</a></li>
|
||||
<li><a href="/operations/components/certification-lifecycle/#beta">Beta</a></li>
|
||||
<li><a href="/operations/components/certification-lifecycle/#stable">Stable</a></li>
|
||||
</ul>
|
||||
<blockquote>
|
||||
<p><code>Since</code>: defines from which Dapr Runtime version, the component is in the current status</p>
|
||||
</blockquote>
|
||||
<blockquote>
|
||||
<p><code>Component version</code>: defines the version of the component</p>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
|
|
Loading…
Reference in New Issue