mirror of https://github.com/dapr/docs.git
Merge pull request #1110 from dapr/periodic-v0.11-merge
Move applicable changes into 0.11
This commit is contained in:
commit
3bd39e9d9f
|
@ -1,3 +1,7 @@
|
|||
[submodule "daprdocs/themes/docsy"]
|
||||
path = daprdocs/themes/docsy
|
||||
url = https://github.com/google/docsy.git
|
||||
[submodule "sdkdocs/python"]
|
||||
path = sdkdocs/python
|
||||
url = https://github.com/dapr/python-sdk.git
|
||||
|
|
@ -2,14 +2,13 @@
|
|||
baseURL = "https://docs.dapr.io/"
|
||||
title = "Dapr Docs"
|
||||
theme = "docsy"
|
||||
disableFastRender = true
|
||||
|
||||
enableRobotsTXT = true
|
||||
enableGitInfo = true
|
||||
|
||||
# Language Configuration
|
||||
languageCode = "en-us"
|
||||
contentDir = "content/en"
|
||||
defaultContentLanguage = "en"
|
||||
|
||||
# Disable categories & tags
|
||||
disableKinds = ["taxonomy", "term"]
|
||||
|
@ -18,6 +17,33 @@ disableKinds = ["taxonomy", "term"]
|
|||
[services.googleAnalytics]
|
||||
id = "UA-149338238-3"
|
||||
|
||||
# Mounts
|
||||
[module]
|
||||
[[module.mounts]]
|
||||
source = "content/en"
|
||||
target = "content"
|
||||
[[module.mounts]]
|
||||
source = "static"
|
||||
target = "static"
|
||||
[[module.mounts]]
|
||||
source = "layouts"
|
||||
target = "layouts"
|
||||
[[module.mounts]]
|
||||
source = "data"
|
||||
target = "data"
|
||||
[[module.mounts]]
|
||||
source = "assets"
|
||||
target = "assets"
|
||||
[[module.mounts]]
|
||||
source = "archetypes"
|
||||
target = "archetypes"
|
||||
[[module.mounts]]
|
||||
source = "../sdkdocs/python/daprdocs/content/en/python-sdk-docs"
|
||||
target = "content/developing-applications/sdks/python"
|
||||
[[module.mounts]]
|
||||
source = "../sdkdocs/python/daprdocs/content/en/python-sdk-contributing"
|
||||
target = "content/contributing/"
|
||||
|
||||
# Markdown Engine - Allow inline html
|
||||
[markup]
|
||||
[markup.goldmark]
|
||||
|
|
|
@ -1,104 +0,0 @@
|
|||
---
|
||||
type: docs
|
||||
title: "Introduction to actors"
|
||||
linkTitle: "Actors background"
|
||||
weight: 20
|
||||
description: Learn more about the actor pattern
|
||||
---
|
||||
|
||||
The [actor pattern](https://en.wikipedia.org/wiki/Actor_model) describes **actors** as the lowest-level "unit of computation". In other words, you write your code in a self-contained unit (called an actor) that receives messages and processes them one at a time, without any kind of concurrency or threading.
|
||||
|
||||
While your code processes a message, it can send one or more messages to other actors, or create new actors. An underlying **runtime** manages how, when and where each actor runs, and also routes messages between actors.
|
||||
|
||||
A large number of actors can execute simultaneously, and actors execute independently from each other.
|
||||
|
||||
Dapr includes a runtime that specifically implements the [Virtual Actor pattern](https://www.microsoft.com/en-us/research/project/orleans-virtual-actors/). With Dapr's implementation, you write your Dapr actors according to the Actor model, and Dapr leverages the scalability and reliability guarantees that the underlying platform provides.
|
||||
|
||||
## Quick links
|
||||
|
||||
- [Dapr Actor Features]({{< ref actors-overview.md >}})
|
||||
- [Dapr Actor API Spec]({{< ref actors_api.md >}} )
|
||||
|
||||
### When to use actors
|
||||
|
||||
As with any other technology decision, you should decide whether to use actors based on the problem you're trying to solve.
|
||||
|
||||
The actor design pattern can be a good fit to a number of distributed systems problems and scenarios, but the first thing you should consider are the constraints of the pattern. Generally speaking, consider the actor pattern to model your problem or scenario if:
|
||||
|
||||
* Your problem space involves a large number (thousands or more) of small, independent, and isolated units of state and logic.
|
||||
* You want to work with single-threaded objects that do not require significant interaction from external components, including querying state across a set of actors.
|
||||
* Your actor instances won't block callers with unpredictable delays by issuing I/O operations.
|
||||
|
||||
## Actors in dapr
|
||||
|
||||
Every actor is defined as an instance of an actor type, identical to the way an object is an instance of a class. For example, there may be an actor type that implements the functionality of a calculator and there could be many actors of that type that are distributed on various nodes across a cluster. Each such actor is uniquely identified by an actor ID.
|
||||
|
||||
<img src="/images/actor_background_game_example.png" width=400>
|
||||
|
||||
## Actor lifetime
|
||||
|
||||
Dapr actors are virtual, meaning that their lifetime is not tied to their in-memory representation. As a result, they do not need to be explicitly created or destroyed. The Dapr actors runtime automatically activates an actor the first time it receives a request for that actor ID. If an actor is not used for a period of time, the Dapr Actors runtime garbage-collects the in-memory object. It will also maintain knowledge of the actor's existence should it need to be reactivated later.
|
||||
|
||||
Invocation of actor methods and reminders reset the idle time, e.g. reminder firing will keep the actor active. Actor reminders fire whether an actor is active or inactive, if fired for inactive actor, it will activate the actor first. Actor timers do not reset the idle time, so timer firing will not keep the actor active. Timers only fire while the actor is active.
|
||||
|
||||
The idle timeout and scan interval Dapr runtime uses to see if an actor can be garbage-collected is configurable. This information can be passed when Dapr runtime calls into the actor service to get supported actor types.
|
||||
|
||||
This virtual actor lifetime abstraction carries some caveats as a result of the virtual actor model, and in fact the Dapr Actors implementation deviates at times from this model.
|
||||
|
||||
An actor is automatically activated (causing an actor object to be constructed) the first time a message is sent to its actor ID. After some period of time, the actor object is garbage collected. In the future, using the actor ID again, causes a new actor object to be constructed. An actor's state outlives the object's lifetime as state is stored in configured state provider for Dapr runtime.
|
||||
|
||||
## Distribution and failover
|
||||
|
||||
To provide scalability and reliability, actors instances are distributed throughout the cluster and Dapr automatically migrates them from failed nodes to healthy ones as required.
|
||||
|
||||
Actors are distributed across the instances of the actor service, and those instance are distributed across the nodes in a cluster. Each service instance contains a set of actors for a given actor type.
|
||||
|
||||
### Actor placement service
|
||||
The Dapr actor runtime manages distribution scheme and key range settings for you. This is done by the actor `Placement` service. When a new instance of a service is created, the corresponding Dapr runtime registers the actor types it can create and the `Placement` service calculates the partitioning across all the instances for a given actor type. This table of partition information for each actor type is updated and stored in each Dapr instance running in the environment and can change dynamically as new instance of actor services are created and destroyed. This is shown in the diagram below.
|
||||
|
||||
<img src="/images/actors_background_placement_service_registration.png" width=600>
|
||||
|
||||
When a client calls an actor with a particular id (for example, actor id 123), the Dapr instance for the client hashes the actor type and id, and uses the information to call onto the corresponding Dapr instance that can serve the requests for that particular actor id. As a result, the same partition (or service instance) is always called for any given actor id. This is shown in the diagram below.
|
||||
|
||||
<img src="/images/actors_background_id_hashing_calling.png" width=600>
|
||||
|
||||
This simplifies some choices but also carries some consideration:
|
||||
|
||||
* By default, actors are randomly placed into pods resulting in uniform distribution.
|
||||
* Because actors are randomly placed, it should be expected that actor operations always require network communication, including serialization and deserialization of method call data, incurring latency and overhead.
|
||||
|
||||
Note: The Dapr actor Placement service is only used for actor placement and therefore is not needed if your services are not using Dapr actors. The Placement service can run in all [hosting environments]({{< ref hosting >}}), including self-hosted and Kubernetes.
|
||||
|
||||
## Actor communication
|
||||
|
||||
You can interact with Dapr to invoke the actor method by calling HTTP/gRPC endpoint.
|
||||
|
||||
```bash
|
||||
POST/GET/PUT/DELETE http://localhost:3500/v1.0/actors/<actorType>/<actorId>/<method/state/timers/reminders>
|
||||
```
|
||||
|
||||
You can provide any data for the actor method in the request body, and the response for the request would be in the response body which is the data from actor call.
|
||||
|
||||
Refer to [Dapr Actor Features]({{< ref actors-overview.md >}}) for more details.
|
||||
|
||||
### Concurrency
|
||||
|
||||
The Dapr Actors runtime provides a simple turn-based access model for accessing actor methods. This means that no more than one thread can be active inside an actor object's code at any time. Turn-based access greatly simplifies concurrent systems as there is no need for synchronization mechanisms for data access. It also means systems must be designed with special considerations for the single-threaded access nature of each actor instance.
|
||||
|
||||
A single actor instance cannot process more than one request at a time. An actor instance can cause a throughput bottleneck if it is expected to handle concurrent requests.
|
||||
|
||||
Actors can deadlock on each other if there is a circular request between two actors while an external request is made to one of the actors simultaneously. The Dapr actor runtime automatically times out on actor calls and throw an exception to the caller to interrupt possible deadlock situations.
|
||||
|
||||
<img src="/images/actors_background_communication.png" width=600>
|
||||
|
||||
|
||||
### Turn-based access
|
||||
|
||||
A turn consists of the complete execution of an actor method in response to a request from other actors or clients, or the complete execution of a timer/reminder callback. Even though these methods and callbacks are asynchronous, the Dapr Actors runtime does not interleave them. A turn must be fully finished before a new turn is allowed. In other words, an actor method or timer/reminder callback that is currently executing must be fully finished before a new call to a method or callback is allowed. A method or callback is considered to have finished if the execution has returned from the method or callback and the task returned by the method or callback has finished. It is worth emphasizing that turn-based concurrency is respected even across different methods, timers, and callbacks.
|
||||
|
||||
The Dapr actors runtime enforces turn-based concurrency by acquiring a per-actor lock at the beginning of a turn and releasing the lock at the end of the turn. Thus, turn-based concurrency is enforced on a per-actor basis and not across actors. Actor methods and timer/reminder callbacks can execute simultaneously on behalf of different actors.
|
||||
|
||||
The following example illustrates the above concepts. Consider an actor type that implements two asynchronous methods (say, Method1 and Method2), a timer, and a reminder. The diagram below shows an example of a timeline for the execution of these methods and callbacks on behalf of two actors (ActorId1 and ActorId2) that belong to this actor type.
|
||||
|
||||
<img src="/images/actors_background_concurrency.png" width=600>
|
||||
|
|
@ -4,134 +4,99 @@ title: "Dapr actors overview"
|
|||
linkTitle: "Overview"
|
||||
weight: 10
|
||||
description: Overview of Dapr support for actors
|
||||
aliases:
|
||||
- "/developing-applications/building-blocks/actors/actors-background"
|
||||
---
|
||||
|
||||
The Dapr actors runtime provides support for [virtual actors]({{< ref actors-background.md >}}) through following capabilities:
|
||||
## Background
|
||||
The [actor pattern](https://en.wikipedia.org/wiki/Actor_model) describes actors as the lowest-level "unit of computation". In other words, you write your code in a self-contained unit (called an actor) that receives messages and processes them one at a time, without any kind of concurrency or threading.
|
||||
|
||||
## Actor method invocation
|
||||
While your code processes a message, it can send one or more messages to other actors, or create new actors. An underlying runtime manages how, when and where each actor runs, and also routes messages between actors.
|
||||
|
||||
You can interact with Dapr to invoke the actor method by calling HTTP/gRPC endpoint
|
||||
A large number of actors can execute simultaneously, and actors execute independently from each other.
|
||||
|
||||
Dapr includes a runtime that specifically implements the [Virtual Actor pattern](https://www.microsoft.com/en-us/research/project/orleans-virtual-actors/). With Dapr's implementation, you write your Dapr actors according to the Actor model, and Dapr leverages the scalability and reliability guarantees that the underlying platform provides.
|
||||
|
||||
### When to use actors
|
||||
|
||||
As with any other technology decision, you should decide whether to use actors based on the problem you're trying to solve.
|
||||
|
||||
The actor design pattern can be a good fit to a number of distributed systems problems and scenarios, but the first thing you should consider are the constraints of the pattern. Generally speaking, consider the actor pattern to model your problem or scenario if:
|
||||
|
||||
* Your problem space involves a large number (thousands or more) of small, independent, and isolated units of state and logic.
|
||||
* You want to work with single-threaded objects that do not require significant interaction from external components, including querying state across a set of actors.
|
||||
* Your actor instances won't block callers with unpredictable delays by issuing I/O operations.
|
||||
|
||||
## Actors in dapr
|
||||
|
||||
Every actor is defined as an instance of an actor type, identical to the way an object is an instance of a class. For example, there may be an actor type that implements the functionality of a calculator and there could be many actors of that type that are distributed on various nodes across a cluster. Each such actor is uniquely identified by an actor ID.
|
||||
|
||||
<img src="/images/actor_background_game_example.png" width=400>
|
||||
|
||||
## Actor lifetime
|
||||
|
||||
Dapr actors are virtual, meaning that their lifetime is not tied to their in-memory representation. As a result, they do not need to be explicitly created or destroyed. The Dapr actors runtime automatically activates an actor the first time it receives a request for that actor ID. If an actor is not used for a period of time, the Dapr Actors runtime garbage-collects the in-memory object. It will also maintain knowledge of the actor's existence should it need to be reactivated later.
|
||||
|
||||
Invocation of actor methods and reminders reset the idle time, e.g. reminder firing will keep the actor active. Actor reminders fire whether an actor is active or inactive, if fired for inactive actor, it will activate the actor first. Actor timers do not reset the idle time, so timer firing will not keep the actor active. Timers only fire while the actor is active.
|
||||
|
||||
The idle timeout and scan interval Dapr runtime uses to see if an actor can be garbage-collected is configurable. This information can be passed when Dapr runtime calls into the actor service to get supported actor types.
|
||||
|
||||
This virtual actor lifetime abstraction carries some caveats as a result of the virtual actor model, and in fact the Dapr Actors implementation deviates at times from this model.
|
||||
|
||||
An actor is automatically activated (causing an actor object to be constructed) the first time a message is sent to its actor ID. After some period of time, the actor object is garbage collected. In the future, using the actor ID again, causes a new actor object to be constructed. An actor's state outlives the object's lifetime as state is stored in configured state provider for Dapr runtime.
|
||||
|
||||
## Distribution and failover
|
||||
|
||||
To provide scalability and reliability, actors instances are distributed throughout the cluster and Dapr automatically migrates them from failed nodes to healthy ones as required.
|
||||
|
||||
Actors are distributed across the instances of the actor service, and those instance are distributed across the nodes in a cluster. Each service instance contains a set of actors for a given actor type.
|
||||
|
||||
### Actor placement service
|
||||
The Dapr actor runtime manages distribution scheme and key range settings for you. This is done by the actor `Placement` service. When a new instance of a service is created, the corresponding Dapr runtime registers the actor types it can create and the `Placement` service calculates the partitioning across all the instances for a given actor type. This table of partition information for each actor type is updated and stored in each Dapr instance running in the environment and can change dynamically as new instance of actor services are created and destroyed. This is shown in the diagram below.
|
||||
|
||||
<img src="/images/actors_background_placement_service_registration.png" width=600>
|
||||
|
||||
When a client calls an actor with a particular id (for example, actor id 123), the Dapr instance for the client hashes the actor type and id, and uses the information to call onto the corresponding Dapr instance that can serve the requests for that particular actor id. As a result, the same partition (or service instance) is always called for any given actor id. This is shown in the diagram below.
|
||||
|
||||
<img src="/images/actors_background_id_hashing_calling.png" width=600>
|
||||
|
||||
This simplifies some choices but also carries some consideration:
|
||||
|
||||
* By default, actors are randomly placed into pods resulting in uniform distribution.
|
||||
* Because actors are randomly placed, it should be expected that actor operations always require network communication, including serialization and deserialization of method call data, incurring latency and overhead.
|
||||
|
||||
Note: The Dapr actor Placement service is only used for actor placement and therefore is not needed if your services are not using Dapr actors. The Placement service can run in all [hosting environments]({{< ref hosting >}}), including self-hosted and Kubernetes.
|
||||
|
||||
## Actor communication
|
||||
|
||||
You can interact with Dapr to invoke the actor method by calling HTTP/gRPC endpoint.
|
||||
|
||||
```bash
|
||||
POST/GET/PUT/DELETE http://localhost:3500/v1.0/actors/<actorType>/<actorId>/method/<method>
|
||||
POST/GET/PUT/DELETE http://localhost:3500/v1.0/actors/<actorType>/<actorId>/<method/state/timers/reminders>
|
||||
```
|
||||
|
||||
You can provide any data for the actor method in the request body and the response for the request is in response body which is data from actor method call.
|
||||
You can provide any data for the actor method in the request body, and the response for the request would be in the response body which is the data from actor call.
|
||||
|
||||
Refer [api spec]({{< ref "actors_api.md#invoke-actor-method" >}}) for more details.
|
||||
Refer to [Dapr Actor Features]({{< ref actors-overview.md >}}) for more details.
|
||||
|
||||
## Actor state management
|
||||
### Concurrency
|
||||
|
||||
Actors can save state reliably using state management capability.
|
||||
The Dapr Actors runtime provides a simple turn-based access model for accessing actor methods. This means that no more than one thread can be active inside an actor object's code at any time. Turn-based access greatly simplifies concurrent systems as there is no need for synchronization mechanisms for data access. It also means systems must be designed with special considerations for the single-threaded access nature of each actor instance.
|
||||
|
||||
You can interact with Dapr through HTTP/gRPC endpoints for state management.
|
||||
A single actor instance cannot process more than one request at a time. An actor instance can cause a throughput bottleneck if it is expected to handle concurrent requests.
|
||||
|
||||
To use actors, your state store must support multi-item transactions. This means your state store [component](https://github.com/dapr/components-contrib/tree/master/state) must implement the [TransactionalStore](https://github.com/dapr/components-contrib/blob/master/state/transactional_store.go) interface. The following state stores implement this interface:
|
||||
Actors can deadlock on each other if there is a circular request between two actors while an external request is made to one of the actors simultaneously. The Dapr actor runtime automatically times out on actor calls and throw an exception to the caller to interrupt possible deadlock situations.
|
||||
|
||||
- Redis
|
||||
- MongoDB
|
||||
- PostgreSQL
|
||||
- SQL Server
|
||||
- Azure CosmosDB
|
||||
<img src="/images/actors_background_communication.png" width=600>
|
||||
|
||||
## Actor timers and reminders
|
||||
|
||||
Actors can schedule periodic work on themselves by registering either timers or reminders.
|
||||
### Turn-based access
|
||||
|
||||
### Actor timers
|
||||
A turn consists of the complete execution of an actor method in response to a request from other actors or clients, or the complete execution of a timer/reminder callback. Even though these methods and callbacks are asynchronous, the Dapr Actors runtime does not interleave them. A turn must be fully finished before a new turn is allowed. In other words, an actor method or timer/reminder callback that is currently executing must be fully finished before a new call to a method or callback is allowed. A method or callback is considered to have finished if the execution has returned from the method or callback and the task returned by the method or callback has finished. It is worth emphasizing that turn-based concurrency is respected even across different methods, timers, and callbacks.
|
||||
|
||||
You can register a callback on actor to be executed based on a timer.
|
||||
The Dapr actors runtime enforces turn-based concurrency by acquiring a per-actor lock at the beginning of a turn and releasing the lock at the end of the turn. Thus, turn-based concurrency is enforced on a per-actor basis and not across actors. Actor methods and timer/reminder callbacks can execute simultaneously on behalf of different actors.
|
||||
|
||||
The Dapr actor runtime ensures that the callback methods respect the turn-based concurrency guarantees.This means that no other actor methods or timer/reminder callbacks will be in progress until this callback completes execution.
|
||||
The following example illustrates the above concepts. Consider an actor type that implements two asynchronous methods (say, Method1 and Method2), a timer, and a reminder. The diagram below shows an example of a timeline for the execution of these methods and callbacks on behalf of two actors (ActorId1 and ActorId2) that belong to this actor type.
|
||||
|
||||
The next period of the timer starts after the callback completes execution. This implies that the timer is stopped while the callback is executing and is started when the callback finishes.
|
||||
<img src="/images/actors_background_concurrency.png" width=600>
|
||||
|
||||
The Dapr actors runtime saves changes made to the actor's state when the callback finishes. If an error occurs in saving the state, that actor object is deactivated and a new instance will be activated.
|
||||
|
||||
All timers are stopped when the actor is deactivated as part of garbage collection. No timer callbacks are invoked after that. Also, the Dapr actors runtime does not retain any information about the timers that were running before deactivation. It is up to the actor to register any timers that it needs when it is reactivated in the future.
|
||||
|
||||
You can create a timer for an actor by calling the HTTP/gRPC request to Dapr.
|
||||
|
||||
```http
|
||||
POST/PUT http://localhost:3500/v1.0/actors/<actorType>/<actorId>/timers/<name>
|
||||
```
|
||||
|
||||
The timer `duetime` and callback are specified in the request body. The due time represents when the timer will first fire after registration. The `period` represents how often the timer fires after that. A due time of 0 means to fire immediately. Negative due times and negative periods are invalid.
|
||||
|
||||
The following request body configures a timer with a `dueTime` of 9 seconds and a `period` of 3 seconds. This means it will first fire after 9 seconds, then every 3 seconds after that.
|
||||
```json
|
||||
{
|
||||
"dueTime":"0h0m9s0ms",
|
||||
"period":"0h0m3s0ms"
|
||||
}
|
||||
```
|
||||
|
||||
The following request body configures a timer with a `dueTime` 0 seconds and a `period` of 3 seconds. This means it fires immediately after registration, then every 3 seconds after that.
|
||||
```json
|
||||
{
|
||||
"dueTime":"0h0m0s0ms",
|
||||
"period":"0h0m3s0ms"
|
||||
}
|
||||
```
|
||||
|
||||
You can remove the actor timer by calling
|
||||
|
||||
```http
|
||||
DELETE http://localhost:3500/v1.0/actors/<actorType>/<actorId>/timers/<name>
|
||||
```
|
||||
|
||||
Refer [api spec]({{< ref "actors_api.md#invoke-timer" >}}) for more details.
|
||||
|
||||
### Actor reminders
|
||||
|
||||
Reminders are a mechanism to trigger *persistent* callbacks on an actor at specified times. Their functionality is similar to timers. But unlike timers, reminders are triggered under all circumstances until the actor explicitly unregisters them or the actor is explicitly deleted. Specifically, reminders are triggered across actor deactivations and failovers because the Dapr actors runtime persists the information about the actors' reminders using Dapr actor state provider.
|
||||
|
||||
You can create a persistent reminder for an actor by calling the Http/gRPC request to Dapr.
|
||||
|
||||
```http
|
||||
POST/PUT http://localhost:3500/v1.0/actors/<actorType>/<actorId>/reminders/<name>
|
||||
```
|
||||
|
||||
The reminder `duetime` and callback can be specified in the request body. The due time represents when the reminder first fires after registration. The `period` represents how often the reminder will fire after that. A due time of 0 means to fire immediately. Negative due times and negative periods are invalid. To register a reminder that fires only once, set the period to an empty string.
|
||||
|
||||
The following request body configures a reminder with a `dueTime` 9 seconds and a `period` of 3 seconds. This means it will first fire after 9 seconds, then every 3 seconds after that.
|
||||
```json
|
||||
{
|
||||
"dueTime":"0h0m9s0ms",
|
||||
"period":"0h0m3s0ms"
|
||||
}
|
||||
```
|
||||
|
||||
The following request body configures a reminder with a `dueTime` 0 seconds and a `period` of 3 seconds. This means it will fire immediately after registration, then every 3 seconds after that.
|
||||
```json
|
||||
{
|
||||
"dueTime":"0h0m0s0ms",
|
||||
"period":"0h0m3s0ms"
|
||||
}
|
||||
```
|
||||
|
||||
The following request body configures a reminder with a `dueTime` 15 seconds and a `period` of empty string. This means it will first fire after 15 seconds, then never fire again.
|
||||
```json
|
||||
{
|
||||
"dueTime":"0h0m15s0ms",
|
||||
"period":""
|
||||
}
|
||||
```
|
||||
|
||||
#### Retrieve actor reminder
|
||||
|
||||
You can retrieve the actor reminder by calling
|
||||
|
||||
```http
|
||||
GET http://localhost:3500/v1.0/actors/<actorType>/<actorId>/reminders/<name>
|
||||
```
|
||||
|
||||
#### Remove the actor reminder
|
||||
|
||||
You can remove the actor reminder by calling
|
||||
|
||||
```http
|
||||
DELETE http://localhost:3500/v1.0/actors/<actorType>/<actorId>/reminders/<name>
|
||||
```
|
||||
|
||||
Refer [api spec]({{< ref "actors_api.md#invoke-reminder" >}}) for more details.
|
||||
|
|
|
@ -0,0 +1,137 @@
|
|||
---
|
||||
type: docs
|
||||
title: "How-to: Use virtual actors in Dapr"
|
||||
linkTitle: "How-To: Virtual actors"
|
||||
weight: 20
|
||||
description: Learn more about the actor pattern
|
||||
---
|
||||
|
||||
The Dapr actors runtime provides support for [virtual actors]({{< ref actors-overview.md >}}) through following capabilities:
|
||||
|
||||
## Actor method invocation
|
||||
|
||||
You can interact with Dapr to invoke the actor method by calling HTTP/gRPC endpoint
|
||||
|
||||
```html
|
||||
POST/GET/PUT/DELETE http://localhost:3500/v1.0/actors/<actorType>/<actorId>/method/<method>
|
||||
```
|
||||
|
||||
You can provide any data for the actor method in the request body and the response for the request is in response body which is data from actor method call.
|
||||
|
||||
Refer [api spec]({{< ref "actors_api.md#invoke-actor-method" >}}) for more details.
|
||||
|
||||
## Actor state management
|
||||
|
||||
Actors can save state reliably using state management capability.
|
||||
|
||||
You can interact with Dapr through HTTP/gRPC endpoints for state management.
|
||||
|
||||
To use actors, your state store must support multi-item transactions. This means your state store [component](https://github.com/dapr/components-contrib/tree/master/state) must implement the [TransactionalStore](https://github.com/dapr/components-contrib/blob/master/state/transactional_store.go) interface. The following state stores implement this interface:
|
||||
|
||||
- Redis
|
||||
- MongoDB
|
||||
- PostgreSQL
|
||||
- SQL Server
|
||||
- Azure CosmosDB
|
||||
|
||||
## Actor timers and reminders
|
||||
|
||||
Actors can schedule periodic work on themselves by registering either timers or reminders.
|
||||
|
||||
### Actor timers
|
||||
|
||||
You can register a callback on actor to be executed based on a timer.
|
||||
|
||||
The Dapr actor runtime ensures that the callback methods respect the turn-based concurrency guarantees.This means that no other actor methods or timer/reminder callbacks will be in progress until this callback completes execution.
|
||||
|
||||
The next period of the timer starts after the callback completes execution. This implies that the timer is stopped while the callback is executing and is started when the callback finishes.
|
||||
|
||||
The Dapr actors runtime saves changes made to the actor's state when the callback finishes. If an error occurs in saving the state, that actor object is deactivated and a new instance will be activated.
|
||||
|
||||
All timers are stopped when the actor is deactivated as part of garbage collection. No timer callbacks are invoked after that. Also, the Dapr actors runtime does not retain any information about the timers that were running before deactivation. It is up to the actor to register any timers that it needs when it is reactivated in the future.
|
||||
|
||||
You can create a timer for an actor by calling the HTTP/gRPC request to Dapr.
|
||||
|
||||
```md
|
||||
POST/PUT http://localhost:3500/v1.0/actors/<actorType>/<actorId>/timers/<name>
|
||||
```
|
||||
|
||||
The timer `duetime` and callback are specified in the request body. The due time represents when the timer will first fire after registration. The `period` represents how often the timer fires after that. A due time of 0 means to fire immediately. Negative due times and negative periods are invalid.
|
||||
|
||||
The following request body configures a timer with a `dueTime` of 9 seconds and a `period` of 3 seconds. This means it will first fire after 9 seconds, then every 3 seconds after that.
|
||||
```json
|
||||
{
|
||||
"dueTime":"0h0m9s0ms",
|
||||
"period":"0h0m3s0ms"
|
||||
}
|
||||
```
|
||||
|
||||
The following request body configures a timer with a `dueTime` 0 seconds and a `period` of 3 seconds. This means it fires immediately after registration, then every 3 seconds after that.
|
||||
```json
|
||||
{
|
||||
"dueTime":"0h0m0s0ms",
|
||||
"period":"0h0m3s0ms"
|
||||
}
|
||||
```
|
||||
|
||||
You can remove the actor timer by calling
|
||||
|
||||
```md
|
||||
DELETE http://localhost:3500/v1.0/actors/<actorType>/<actorId>/timers/<name>
|
||||
```
|
||||
|
||||
Refer [api spec]({{< ref "actors_api.md#invoke-timer" >}}) for more details.
|
||||
|
||||
### Actor reminders
|
||||
|
||||
Reminders are a mechanism to trigger *persistent* callbacks on an actor at specified times. Their functionality is similar to timers. But unlike timers, reminders are triggered under all circumstances until the actor explicitly unregisters them or the actor is explicitly deleted. Specifically, reminders are triggered across actor deactivations and failovers because the Dapr actors runtime persists the information about the actors' reminders using Dapr actor state provider.
|
||||
|
||||
You can create a persistent reminder for an actor by calling the Http/gRPC request to Dapr.
|
||||
|
||||
```md
|
||||
POST/PUT http://localhost:3500/v1.0/actors/<actorType>/<actorId>/reminders/<name>
|
||||
```
|
||||
|
||||
The reminder `duetime` and callback can be specified in the request body. The due time represents when the reminder first fires after registration. The `period` represents how often the reminder will fire after that. A due time of 0 means to fire immediately. Negative due times and negative periods are invalid. To register a reminder that fires only once, set the period to an empty string.
|
||||
|
||||
The following request body configures a reminder with a `dueTime` 9 seconds and a `period` of 3 seconds. This means it will first fire after 9 seconds, then every 3 seconds after that.
|
||||
```json
|
||||
{
|
||||
"dueTime":"0h0m9s0ms",
|
||||
"period":"0h0m3s0ms"
|
||||
}
|
||||
```
|
||||
|
||||
The following request body configures a reminder with a `dueTime` 0 seconds and a `period` of 3 seconds. This means it will fire immediately after registration, then every 3 seconds after that.
|
||||
```json
|
||||
{
|
||||
"dueTime":"0h0m0s0ms",
|
||||
"period":"0h0m3s0ms"
|
||||
}
|
||||
```
|
||||
|
||||
The following request body configures a reminder with a `dueTime` 15 seconds and a `period` of empty string. This means it will first fire after 15 seconds, then never fire again.
|
||||
```json
|
||||
{
|
||||
"dueTime":"0h0m15s0ms",
|
||||
"period":""
|
||||
}
|
||||
```
|
||||
|
||||
#### Retrieve actor reminder
|
||||
|
||||
You can retrieve the actor reminder by calling
|
||||
|
||||
```md
|
||||
GET http://localhost:3500/v1.0/actors/<actorType>/<actorId>/reminders/<name>
|
||||
```
|
||||
|
||||
#### Remove the actor reminder
|
||||
|
||||
You can remove the actor reminder by calling
|
||||
|
||||
```md
|
||||
DELETE http://localhost:3500/v1.0/actors/<actorType>/<actorId>/reminders/<name>
|
||||
```
|
||||
|
||||
Refer [api spec]({{< ref "actors_api.md#invoke-reminder" >}}) for more details.
|
|
@ -14,17 +14,23 @@ Dealing with different databases libraries, testing them, handling retries and f
|
|||
Dapr provides state management capabilities that include consistency and concurrency options.
|
||||
In this guide we'll start of with the basics: Using the key/value state API to allow an application to save, get and delete state.
|
||||
|
||||
## Pre-requisites
|
||||
|
||||
- [Dapr CLI]({{< ref install-dapr-cli.md >}})
|
||||
- Initialized [Dapr environment]({{< ref install-dapr-selfhost.md >}})
|
||||
|
||||
## Step 1: Setup a state store
|
||||
|
||||
A state store component represents a resource that Dapr uses to communicate with a database.
|
||||
For the purpose of this how to we'll use a Redis state store, but any state store from the [supported list]({{< ref supported-state-stores >}}) will work.
|
||||
|
||||
For the purpose of this guide we'll use a Redis state store, but any state store from the [supported list]({{< ref supported-state-stores >}}) will work.
|
||||
|
||||
{{< tabs "Self-Hosted (CLI)" Kubernetes>}}
|
||||
|
||||
{{% codetab %}}
|
||||
When using `dapr init` in Standalone mode, the Dapr CLI automatically provisions a state store (Redis) and creates the relevant YAML in a `components` directory, which for Linux/MacOS is `$HOME/.dapr/components` and for Windows is `%USERPROFILE%\.dapr\components`
|
||||
|
||||
To change the state store being used, replace the YAML under `/components` with the file of your choice.
|
||||
To optionally change the state store being used, replace the YAML file `statestore.yaml` under `/components` with the file of your choice.
|
||||
{{% /codetab %}}
|
||||
|
||||
{{% codetab %}}
|
||||
|
@ -33,104 +39,105 @@ See the instructions [here]({{< ref "setup-state-store" >}}) on how to setup dif
|
|||
|
||||
{{< /tabs >}}
|
||||
|
||||
## Step 2: Save state
|
||||
## Step 2: Save and retrieve a single state
|
||||
|
||||
The following example shows how to save two key/value pairs in a single call using the state management API.
|
||||
The following example shows how to a single key/value pair using the Dapr state building block.
|
||||
|
||||
{{% alert title="Note" color="warning" %}}
|
||||
It is important to set an app-id, as the state keys are prefixed with this value. If you don't set it one is generated for you at runtime, and the next time you run the command a new one will be generated and you will no longer be able to access previously saved state.
|
||||
{{% /alert %}}
|
||||
|
||||
{{< tabs "HTTP API (Bash)" "HTTP API (PowerShell)" "Python SDK">}}
|
||||
|
||||
{{% codetab %}}
|
||||
Begin by ensuring a Dapr sidecar is running:
|
||||
Begin by launching a Dapr sidecar:
|
||||
|
||||
```bash
|
||||
dapr run --app-id myapp --dapr-http-port 3500
|
||||
```
|
||||
{{% alert title="Note" color="info" %}}
|
||||
It is important to set an app-id, as the state keys are prefixed with this value. If you don't set it one is generated for you at runtime, and the next time you run the command a new one will be generated and you will no longer be able to access previously saved state.
|
||||
|
||||
{{% /alert %}}
|
||||
|
||||
Then in a separate terminal run:
|
||||
Then in a separate terminal save a key/value pair into your statestore:
|
||||
```bash
|
||||
curl -X POST -H "Content-Type: application/json" -d '[{ "key": "key1", "value": "value1"}, { "key": "key2", "value": "value2"}]' http://localhost:3500/v1.0/state/statestore
|
||||
curl -X POST -H "Content-Type: application/json" -d '{ "key": "key1", "value": "value1"}' http://localhost:3500/v1.0/state/statestore
|
||||
```
|
||||
|
||||
Now get the state you just saved:
|
||||
```bash
|
||||
curl http://localhost:3500/v1.0/state/statestore/key1
|
||||
```
|
||||
|
||||
You can also restart your sidecar and try retrieving state again to see that state persists separate from the app.
|
||||
{{% /codetab %}}
|
||||
|
||||
{{% codetab %}}
|
||||
Begin by ensuring a Dapr sidecar is running:
|
||||
|
||||
Begin by launching a Dapr sidecar:
|
||||
|
||||
```bash
|
||||
dapr --app-id myapp --port 3500 run
|
||||
```
|
||||
|
||||
{{% alert title="Note" color="info" %}}
|
||||
It is important to set an app-id, as the state keys are prefixed with this value. If you don't set it one is generated for you at runtime, and the next time you run the command a new one will be generated and you will no longer be able to access previously saved state.
|
||||
|
||||
{{% /alert %}}
|
||||
|
||||
Then in a separate terminal run:
|
||||
Then in a separate terminal save a key/value pair into your statestore:
|
||||
```powershell
|
||||
Invoke-RestMethod -Method Post -ContentType 'application/json' -Body '[{ "key": "key1", "value": "value1"}, { "key": "key2", "value": "value2"}]' -Uri 'http://localhost:3500/v1.0/state/statestore'
|
||||
```
|
||||
{{% /codetab %}}
|
||||
|
||||
{{% codetab %}}
|
||||
Make sure to install the Dapr Python SDK with `pip3 install dapr`. Then create a file named `state.py` with:
|
||||
```python
|
||||
from dapr.clients import DaprClient
|
||||
from dapr.clients.grpc._state import StateItem
|
||||
|
||||
with DaprClient() as d:
|
||||
d.save_states(store_name="statestore",
|
||||
states=[
|
||||
StateItem(key="key1", value="value1"),
|
||||
StateItem(key="key2", value="value2")
|
||||
])
|
||||
|
||||
Invoke-RestMethod -Method Post -ContentType 'application/json' -Body '{"key": "key1", "value": "value1"}' -Uri 'http://localhost:3500/v1.0/state/statestore'
|
||||
```
|
||||
|
||||
Run with `dapr run --app-id myapp run python state.py`
|
||||
|
||||
{{% alert title="Note" color="info" %}}
|
||||
It is important to set an app-id, as the state keys are prefixed with this value. If you don't set it one is generated for you at runtime, and the next time you run the command a new one will be generated and you will no longer be able to access previously saved state.
|
||||
|
||||
{{% /alert %}}
|
||||
|
||||
{{% /codetab %}}
|
||||
|
||||
{{< /tabs >}}
|
||||
|
||||
## Step 3: Get state
|
||||
|
||||
The following example shows how to get an item by using a key with the state management API:
|
||||
|
||||
{{< tabs "HTTP API (Bash)" "HTTP API (PowerShell)" "Python SDK">}}
|
||||
|
||||
{{% codetab %}}
|
||||
With the same dapr instance running from above run:
|
||||
```bash
|
||||
curl http://localhost:3500/v1.0/state/statestore/key1
|
||||
```
|
||||
{{% /codetab %}}
|
||||
|
||||
{{% codetab %}}
|
||||
With the same dapr instance running from above run:
|
||||
Now get the state you just saved:
|
||||
```powershell
|
||||
Invoke-RestMethod -Uri 'http://localhost:3500/v1.0/state/statestore/key1'
|
||||
```
|
||||
|
||||
You can also restart your sidecar and try retrieving state again to see that state persists separate from the app.
|
||||
|
||||
{{% /codetab %}}
|
||||
|
||||
{{% codetab %}}
|
||||
Add the following code to `state.py` from above and run again:
|
||||
|
||||
Save the following to a file named `pythonState.py`:
|
||||
|
||||
```python
|
||||
data = d.get_state(store_name="statestore",
|
||||
key="key1",
|
||||
state_metadata={"metakey": "metavalue"}).data
|
||||
from dapr.clients import DaprClient
|
||||
|
||||
with DaprClient() as d:
|
||||
d.save_state(store_name="statestore", key="myFirstKey", value="myFirstValue" )
|
||||
print("State has been stored")
|
||||
|
||||
data = d.get_state(store_name="statestore", key="myFirstKey").data
|
||||
print(f"Got value: {data}")
|
||||
|
||||
```
|
||||
|
||||
Once saved run the following command to launch a Dapr sidecar and run the Python application:
|
||||
|
||||
```bash
|
||||
dapr --app-id myapp run python pythonState.py
|
||||
```
|
||||
|
||||
You should get an output similar to the following, which will show both the Dapr and app logs:
|
||||
|
||||
```md
|
||||
== DAPR == time="2021-01-06T21:34:33.7970377-08:00" level=info msg="starting Dapr Runtime -- version 0.11.3 -- commit a1a8e11" app_id=Braidbald-Boot scope=dapr.runtime type=log ver=0.11.3
|
||||
== DAPR == time="2021-01-06T21:34:33.8040378-08:00" level=info msg="standalone mode configured" app_id=Braidbald-Boot scope=dapr.runtime type=log ver=0.11.3
|
||||
== DAPR == time="2021-01-06T21:34:33.8040378-08:00" level=info msg="app id: Braidbald-Boot" app_id=Braidbald-Boot scope=dapr.runtime type=log ver=0.11.3
|
||||
== DAPR == time="2021-01-06T21:34:33.9750400-08:00" level=info msg="component loaded. name: statestore, type: state.redis" app_id=Braidbald-Boot scope=dapr.runtime type=log ver=0.11.3
|
||||
== DAPR == time="2021-01-06T21:34:33.9760387-08:00" level=info msg="API gRPC server is running on port 51656" app_id=Braidbald-Boot scope=dapr.runtime type=log ver=0.11.3
|
||||
== DAPR == time="2021-01-06T21:34:33.9770372-08:00" level=info msg="dapr initialized. Status: Running. Init Elapsed 172.9994ms" app_id=Braidbald-Boot scope=dapr.
|
||||
|
||||
Checking if Dapr sidecar is listening on GRPC port 51656
|
||||
Dapr sidecar is up and running.
|
||||
Updating metadata for app command: python pythonState.py
|
||||
You are up and running! Both Dapr and your app logs will appear here.
|
||||
|
||||
== APP == State has been stored
|
||||
== APP == Got value: b'myFirstValue'
|
||||
```
|
||||
|
||||
{{% /codetab %}}
|
||||
|
||||
{{< /tabs >}}
|
||||
|
||||
## Step 4: Delete state
|
||||
|
||||
## Step 3: Delete state
|
||||
|
||||
The following example shows how to delete an item by using a key with the state management API:
|
||||
|
||||
|
@ -153,16 +160,231 @@ Try getting state again and note that no value is returned.
|
|||
{{% /codetab %}}
|
||||
|
||||
{{% codetab %}}
|
||||
Add the following code to `state.py` from above and run again:
|
||||
|
||||
Update `pythonState.py` with:
|
||||
|
||||
```python
|
||||
d.delete_state(store_name="statestore"",
|
||||
key="key1",
|
||||
state_metadata={"metakey": "metavalue"})
|
||||
data = d.get_state(store_name="statestore",
|
||||
key="key1",
|
||||
state_metadata={"metakey": "metavalue"}).data
|
||||
from dapr.clients import DaprClient
|
||||
|
||||
with DaprClient() as d:
|
||||
d.save_state(store_name="statestore", key="key1", value="value1" )
|
||||
print("State has been stored")
|
||||
|
||||
data = d.get_state(store_name="statestore", key="key1").data
|
||||
print(f"Got value: {data}")
|
||||
|
||||
d.delete_state(store_name="statestore", key="key1")
|
||||
|
||||
data = d.get_state(store_name="statestore", key="key1").data
|
||||
print(f"Got value after delete: {data}")
|
||||
```
|
||||
|
||||
Now run your program with:
|
||||
|
||||
```bash
|
||||
dapr --app-id myapp run python pythonState.py
|
||||
```
|
||||
|
||||
You should see an output similar to the following:
|
||||
|
||||
```md
|
||||
Starting Dapr with id Yakchocolate-Lord. HTTP Port: 59457. gRPC Port: 59458
|
||||
|
||||
== DAPR == time="2021-01-06T22:55:36.5570696-08:00" level=info msg="starting Dapr Runtime -- version 0.11.3 -- commit a1a8e11" app_id=Yakchocolate-Lord scope=dapr.runtime type=log ver=0.11.3
|
||||
== DAPR == time="2021-01-06T22:55:36.5690367-08:00" level=info msg="standalone mode configured" app_id=Yakchocolate-Lord scope=dapr.runtime type=log ver=0.11.3
|
||||
== DAPR == time="2021-01-06T22:55:36.7220140-08:00" level=info msg="component loaded. name: statestore, type: state.redis" app_id=Yakchocolate-Lord scope=dapr.runtime type=log ver=0.11.3
|
||||
== DAPR == time="2021-01-06T22:55:36.7230148-08:00" level=info msg="API gRPC server is running on port 59458" app_id=Yakchocolate-Lord scope=dapr.runtime type=log ver=0.11.3
|
||||
== DAPR == time="2021-01-06T22:55:36.7240207-08:00" level=info msg="dapr initialized. Status: Running. Init Elapsed 154.984ms" app_id=Yakchocolate-Lord scope=dapr.runtime type=log ver=0.11.3
|
||||
|
||||
Checking if Dapr sidecar is listening on GRPC port 59458
|
||||
Dapr sidecar is up and running.
|
||||
Updating metadata for app command: python pythonState.py
|
||||
You're up and running! Both Dapr and your app logs will appear here.
|
||||
|
||||
== APP == State has been stored
|
||||
== APP == Got value: b'value1'
|
||||
== APP == Got value after delete: b''
|
||||
```
|
||||
{{% /codetab %}}
|
||||
|
||||
{{< /tabs >}}
|
||||
|
||||
## Step 4: Save and retrieve multiple states
|
||||
|
||||
Dapr also allows you to save and retrieve multiple states in the same call.
|
||||
|
||||
{{< tabs "HTTP API (Bash)" "HTTP API (PowerShell)" "Python SDK">}}
|
||||
|
||||
{{% codetab %}}
|
||||
With the same dapr instance running from above save two key/value pairs into your statestore:
|
||||
```bash
|
||||
curl -X POST -H "Content-Type: application/json" -d '[{ "key": "key1", "value": "value1"}, { "key": "key2", "value": "value2"}]' http://localhost:3500/v1.0/state/statestore
|
||||
```
|
||||
|
||||
Now get the states you just saved:
|
||||
```bash
|
||||
curl -X POST -H "Content-Type: application/json" -d '{"keys":["key1", "key2"]}' http://localhost:3500/v1.0/state/statestore/bulk
|
||||
```
|
||||
{{% /codetab %}}
|
||||
|
||||
{{% codetab %}}
|
||||
With the same dapr instance running from above save two key/value pairs into your statestore:
|
||||
```powershell
|
||||
Invoke-RestMethod -Method Post -ContentType 'application/json' -Body '[{ "key": "key1", "value": "value1"}, { "key": "key2", "value": "value2"}]' -Uri 'http://localhost:3500/v1.0/state/statestore'
|
||||
```
|
||||
|
||||
Now get the states you just saved:
|
||||
```powershell
|
||||
Invoke-RestMethod -Method Post -ContentType 'application/json' -Body '{"keys":["key1", "key2"]}' -Uri 'http://localhost:3500/v1.0/state/statestore/bulk'
|
||||
```
|
||||
|
||||
{{% /codetab %}}
|
||||
|
||||
{{% codetab %}}
|
||||
|
||||
The `StateItem` object can be used to store multiple Dapr states with the `save_states` and `get_states` methods.
|
||||
|
||||
Update your `pythonState.py` file with the following code:
|
||||
|
||||
```python
|
||||
from dapr.clients import DaprClient
|
||||
from dapr.clients.grpc._state import StateItem
|
||||
|
||||
with DaprClient() as d:
|
||||
s1 = StateItem(key="key1", value="value1")
|
||||
s2 = StateItem(key="key2", value="value2")
|
||||
|
||||
d.save_states(store_name="statestore", states=[s1,s2])
|
||||
print("States have been stored")
|
||||
|
||||
items = d.get_states(store_name="statestore", keys=["key1", "key2"]).items
|
||||
print(f"Got items: {[i.data for i in items]}")
|
||||
```
|
||||
|
||||
Now run your program with:
|
||||
|
||||
```bash
|
||||
dapr --app-id myapp run python pythonState.py
|
||||
```
|
||||
|
||||
You should see an output similar to the following:
|
||||
|
||||
```md
|
||||
== DAPR == time="2021-01-06T21:54:56.7262358-08:00" level=info msg="starting Dapr Runtime -- version 0.11.3 -- commit a1a8e11" app_id=Musesequoia-Sprite scope=dapr.runtime type=log ver=0.11.3
|
||||
== DAPR == time="2021-01-06T21:54:56.7401933-08:00" level=info msg="standalone mode configured" app_id=Musesequoia-Sprite scope=dapr.runtime type=log ver=0.11.3
|
||||
== DAPR == time="2021-01-06T21:54:56.8754240-08:00" level=info msg="Initialized name resolution to standalone" app_id=Musesequoia-Sprite scope=dapr.runtime type=log ver=0.11.3
|
||||
== DAPR == time="2021-01-06T21:54:56.8844248-08:00" level=info msg="component loaded. name: statestore, type: state.redis" app_id=Musesequoia-Sprite scope=dapr.runtime type=log ver=0.11.3
|
||||
== DAPR == time="2021-01-06T21:54:56.8854273-08:00" level=info msg="API gRPC server is running on port 60614" app_id=Musesequoia-Sprite scope=dapr.runtime type=log ver=0.11.3
|
||||
== DAPR == time="2021-01-06T21:54:56.8854273-08:00" level=info msg="dapr initialized. Status: Running. Init Elapsed 145.234ms" app_id=Musesequoia-Sprite scope=dapr.runtime type=log ver=0.11.3
|
||||
|
||||
Checking if Dapr sidecar is listening on GRPC port 60614
|
||||
Dapr sidecar is up and running.
|
||||
Updating metadata for app command: python pythonState.py
|
||||
You're up and running! Both Dapr and your app logs will appear here.
|
||||
|
||||
== APP == States have been stored
|
||||
== APP == Got items: [b'value1', b'value2']
|
||||
```
|
||||
|
||||
{{% /codetab %}}
|
||||
|
||||
{{< /tabs >}}
|
||||
|
||||
## Step 5: Perform state transactions
|
||||
|
||||
{{% alert title="Note" color="warning" %}}
|
||||
State transactions require a state store that supports multi-item transactions. Visit the [supported state stores page]({{< ref supported-state-stores >}}) page for a full list. Note that the default Redis container created in a self-hosted environment supports them.
|
||||
{{% /alert %}}
|
||||
|
||||
{{< tabs "HTTP API (Bash)" "HTTP API (PowerShell)" "Python SDK" >}}
|
||||
|
||||
{{% codetab %}}
|
||||
With the same dapr instance running from above perform two state transactions:
|
||||
```bash
|
||||
curl -X POST -H "Content-Type: application/json" -d '{"operations": [{"operation":"upsert", "request": {"key": "key1", "value": "newValue1"}}, {"operation":"delete", "request": {"key": "key2"}}]}' http://localhost:3500/v1.0/state/statestore/transaction
|
||||
```
|
||||
|
||||
Now see the results of your state transactions:
|
||||
```bash
|
||||
curl -X POST -H "Content-Type: application/json" -d '{"keys":["key1", "key2"]}' http://localhost:3500/v1.0/state/statestore/bulk
|
||||
```
|
||||
{{% /codetab %}}
|
||||
|
||||
{{% codetab %}}
|
||||
With the same dapr instance running from above save two key/value pairs into your statestore:
|
||||
```powershell
|
||||
Invoke-RestMethod -Method Post -ContentType 'application/json' -Body '{"operations": [{"operation":"upsert", "request": {"key": "key1", "value": "newValue1"}}, {"operation":"delete", "request": {"key": "key2"}}]}' -Uri 'http://localhost:3500/v1.0/state/statestore'
|
||||
```
|
||||
|
||||
Now see the results of your state transactions:
|
||||
```powershell
|
||||
Invoke-RestMethod -Method Post -ContentType 'application/json' -Body '{"keys":["key1", "key2"]}' -Uri 'http://localhost:3500/v1.0/state/statestore/bulk'
|
||||
```
|
||||
|
||||
{{% /codetab %}}
|
||||
|
||||
{{% codetab %}}
|
||||
|
||||
The `TransactionalStateOperation` can perform a state transaction if your state stores need to be transactional.
|
||||
|
||||
Update your `pythonState.py` file with the following code:
|
||||
|
||||
```python
|
||||
from dapr.clients import DaprClient
|
||||
from dapr.clients.grpc._state import StateItem
|
||||
from dapr.clients.grpc._request import TransactionalStateOperation, TransactionOperationType
|
||||
|
||||
with DaprClient() as d:
|
||||
s1 = StateItem(key="key1", value="value1")
|
||||
s2 = StateItem(key="key2", value="value2")
|
||||
|
||||
d.save_states(store_name="statestore", states=[s1,s2])
|
||||
print("States have been stored")
|
||||
|
||||
d.execute_transaction(
|
||||
store_name="statestore",
|
||||
operations=[
|
||||
TransactionalStateOperation(key="key1", data="newValue1", operation_type=TransactionOperationType.upsert),
|
||||
TransactionalStateOperation(key="key2", data="value2", operation_type=TransactionOperationType.delete)
|
||||
]
|
||||
)
|
||||
print("State transactions have been completed")
|
||||
|
||||
items = d.get_states(store_name="statestore", keys=["key1", "key2"]).items
|
||||
print(f"Got items: {[i.data for i in items]}")
|
||||
```
|
||||
|
||||
Now run your program with:
|
||||
|
||||
```bash
|
||||
dapr run python pythonState.py
|
||||
```
|
||||
|
||||
You should see an output similar to the following:
|
||||
|
||||
```md
|
||||
Starting Dapr with id Singerchecker-Player. HTTP Port: 59533. gRPC Port: 59534
|
||||
== DAPR == time="2021-01-06T22:18:14.1246721-08:00" level=info msg="starting Dapr Runtime -- version 0.11.3 -- commit a1a8e11" app_id=Singerchecker-Player scope=dapr.runtime type=log ver=0.11.3
|
||||
== DAPR == time="2021-01-06T22:18:14.1346254-08:00" level=info msg="standalone mode configured" app_id=Singerchecker-Player scope=dapr.runtime type=log ver=0.11.3
|
||||
== DAPR == time="2021-01-06T22:18:14.2747063-08:00" level=info msg="component loaded. name: statestore, type: state.redis" app_id=Singerchecker-Player scope=dapr.runtime type=log ver=0.11.3
|
||||
== DAPR == time="2021-01-06T22:18:14.2757062-08:00" level=info msg="API gRPC server is running on port 59534" app_id=Singerchecker-Player scope=dapr.runtime type=log ver=0.11.3
|
||||
== DAPR == time="2021-01-06T22:18:14.2767059-08:00" level=info msg="dapr initialized. Status: Running. Init Elapsed 142.0805ms" app_id=Singerchecker-Player scope=dapr.runtime type=log ver=0.11.3
|
||||
|
||||
Checking if Dapr sidecar is listening on GRPC port 59534
|
||||
Dapr sidecar is up and running.
|
||||
Updating metadata for app command: python pythonState.py
|
||||
You're up and running! Both Dapr and your app logs will appear here.
|
||||
|
||||
== APP == State transactions have been completed
|
||||
== APP == Got items: [b'value1', b'']
|
||||
```
|
||||
|
||||
{{% /codetab %}}
|
||||
|
||||
{{< /tabs >}}
|
||||
|
||||
## Next steps
|
||||
|
||||
- Read the full [State API reference]({{< ref state_api.md >}})
|
||||
- Try one of the [Dapr SDKs]({{< ref sdks >}})
|
||||
- Build a [stateful service]({{< ref howto-stateful-service.md >}})
|
|
@ -0,0 +1,95 @@
|
|||
---
|
||||
type: docs
|
||||
title: "How-To: Share state between applications"
|
||||
linkTitle: "How-To: Share state between applications"
|
||||
weight: 400
|
||||
description: "Choose different strategies for sharing state between different applications"
|
||||
---
|
||||
|
||||
## Introduction
|
||||
|
||||
Dapr offers developers different ways to share state between applications.
|
||||
|
||||
Different architectures might have different needs when it comes to sharing state. For example, in one scenario you may want to encapsulate all state within a given application and have Dapr manage the access for you. In a different scenario, you may need to have two applications working on the same state be able to get and save the same keys.
|
||||
|
||||
To enable state sharing, Dapr supports the following key prefixes strategies:
|
||||
|
||||
* **`appid`** - This is the default strategy. the `appid` prefix allows state to be managed only by the app with the specified `appid`. All state keys will be prefixed with the `appid`, and are scoped for the application.
|
||||
|
||||
* **`name`** - This setting uses the name of the state store component as the prefix. Multiple applications can share the same state for a given state store.
|
||||
|
||||
* **`none`** - This setting uses no prefixing. Multiple applications share state across different state stores.
|
||||
|
||||
## Specifying a state prefix strategy
|
||||
|
||||
To specify a prefix strategy, add a metadata key named `keyPrefix` on a state component:
|
||||
|
||||
```yaml
|
||||
apiVersion: dapr.io/v1alpha1
|
||||
kind: Component
|
||||
metadata:
|
||||
name: statestore
|
||||
namespace: production
|
||||
spec:
|
||||
type: state.redis
|
||||
version: v1
|
||||
metadata:
|
||||
- name: keyPrefix
|
||||
value: <key-prefix-strategy>
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
The following examples will show you how state retrieval looks like with each of the supported prefix strategies:
|
||||
|
||||
### `appid` (default)
|
||||
|
||||
A Dapr application with app id `myApp` is saving state into a state store named `redis`:
|
||||
|
||||
```shell
|
||||
curl -X POST http://localhost:3500/v1.0/state/redis \
|
||||
-H "Content-Type: application/json"
|
||||
-d '[
|
||||
{
|
||||
"key": "darth",
|
||||
"value": "nihilus"
|
||||
}
|
||||
]'
|
||||
```
|
||||
|
||||
The key will be saved as `myApp||darth`.
|
||||
|
||||
### `name`
|
||||
|
||||
A Dapr application with app id `myApp` is saving state into a state store named `redis`:
|
||||
|
||||
```shell
|
||||
curl -X POST http://localhost:3500/v1.0/state/redis \
|
||||
-H "Content-Type: application/json"
|
||||
-d '[
|
||||
{
|
||||
"key": "darth",
|
||||
"value": "nihilus"
|
||||
}
|
||||
]'
|
||||
```
|
||||
|
||||
The key will be saved as `redis||darth`.
|
||||
|
||||
### `none`
|
||||
|
||||
A Dapr application with app id `myApp` is saving state into a state store named `redis`:
|
||||
|
||||
```shell
|
||||
curl -X POST http://localhost:3500/v1.0/state/redis \
|
||||
-H "Content-Type: application/json"
|
||||
-d '[
|
||||
{
|
||||
"key": "darth",
|
||||
"value": "nihilus"
|
||||
}
|
||||
]'
|
||||
```
|
||||
|
||||
The key will be saved as `darth`.
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
type: docs
|
||||
title: "Work with backend state stores"
|
||||
linkTitle: "Backend stores"
|
||||
weight: 400
|
||||
weight: 500
|
||||
description: "Guides for working with specific backend states stores"
|
||||
---
|
||||
|
||||
|
|
|
@ -8,6 +8,8 @@ description: "Overview of the state management building block"
|
|||
|
||||
## Introduction
|
||||
|
||||
<img src="/images/state-management-overview.png" width=900>
|
||||
|
||||
Dapr offers key/value storage APIs for state management. If a microservice uses state management, it can use these APIs to leverage any of the [supported state stores]({{< ref supported-state-stores.md >}}), without adding or learning a third party SDK.
|
||||
|
||||
When using state management your application can leverage several features that would otherwise be complicated and error-prone to build yourself such as:
|
||||
|
@ -16,39 +18,30 @@ When using state management your application can leverage several features that
|
|||
- Retry policies
|
||||
- Bulk [CRUD](https://en.wikipedia.org/wiki/Create,_read,_update_and_delete) operations
|
||||
|
||||
See below for a diagram of state management's high level architecture.
|
||||
|
||||
<img src="/images/state-management-overview.png" width=900>
|
||||
|
||||
## Features
|
||||
|
||||
- [State management API](#state-management-api)
|
||||
- [State store behaviors](#state-store-behaviors)
|
||||
- [Concurrency](#concurrency)
|
||||
- [Consistency](#consistency)
|
||||
- [Retry policies](#retry-policies)
|
||||
- [Bulk operations](#bulk-operations)
|
||||
- [Querying state store directly](#querying-state-store-directly)
|
||||
|
||||
### State management API
|
||||
|
||||
Developers can use the state management API to retrieve, save and delete state values by providing keys.
|
||||
Developers can use the [state management API]({{< ref state_api.md >}}) to retrieve, save and delete state values by providing keys.
|
||||
|
||||
Dapr data stores are components. Dapr ships with [Redis](https://redis.io) out-of-box for local development in self hosted mode. Dapr allows you to plug in other data stores as components such as [Azure CosmosDB](https://azure.microsoft.com/services/cosmos-db/), [SQL Server](https://azure.microsoft.com/services/sql-database/), [AWS DynamoDB](https://aws.amazon.com/DynamoDB), [GCP Cloud Spanner](https://cloud.google.com/spanner) and [Cassandra](http://cassandra.apache.org/).
|
||||
### Pluggable state stores
|
||||
|
||||
Visit [State API]({{< ref state_api.md >}}) for more information.
|
||||
Dapr data stores are modeled as pluggable components, which can be swapped out without any changes to your service code. Check out the [full list of state stores]({{< ref supported-state-stores >}}) to see what Dapr supports.
|
||||
|
||||
> **NOTE:** Dapr prefixes state keys with the ID of the current Dapr instance. This allows multiple Dapr instances to share the same state store.
|
||||
### Configurable state store behavior
|
||||
|
||||
### State store behaviors
|
||||
Dapr allows developers to attach additional metadata to a state operation request that describes how the request is expected to be handled.
|
||||
|
||||
Dapr allows developers to attach to a state operation request additional metadata that describes how the request is expected to be handled. For example, you can attach concurrency requirements, consistency requirements, and retry policy to any state operation requests.
|
||||
For example, you can attach:
|
||||
- Concurrency requirements
|
||||
- Consistency requirements
|
||||
- Retry policies
|
||||
|
||||
By default, your application should assume a data store is **eventually consistent** and uses a **last-write-wins** concurrency pattern. On the other hand, if you do attach metadata to your requests, Dapr passes the metadata along with the requests to the state store and expects the data store to fulfill the requests.
|
||||
By default, your application should assume a data store is **eventually consistent** and uses a **last-write-wins** concurrency pattern.
|
||||
|
||||
Not all stores are created equal. To ensure portability of your application, you can query the capabilities of the store and make your code adaptive to different store capabilities.
|
||||
Not all stores are created equal. To ensure portability of your application you can query the capabilities of the store and make your code adaptive to different store capabilities.
|
||||
|
||||
The following table summarizes the capabilities of existing data store implementations.
|
||||
The following table gives examples of capabilities of popular data store implementations.
|
||||
|
||||
| Store | Strong consistent write | Strong consistent read | ETag |
|
||||
|-------------------|-------------------------|------------------------|------|
|
||||
|
@ -60,13 +53,15 @@ The following table summarizes the capabilities of existing data store implement
|
|||
|
||||
### Concurrency
|
||||
|
||||
Dapr supports optimistic concurrency control (OCC) using ETags. When a state is requested, Dapr always attaches an **ETag** property to the returned state. And when the user code tries to update or delete a state, it's expected to attach the ETag through the **If-Match** header. The write operation can succeed only when the provided ETag matches with the ETag in the state store.
|
||||
Dapr supports optimistic concurrency control (OCC) using ETags. When a state is requested, Dapr always attaches an **ETag** property to the returned state. When the user code tries to update or delete a state, it's expected to attach the ETag through the **If-Match** header. The write operation can succeed only when the provided ETag matches with the ETag in the state store.
|
||||
|
||||
Dapr chooses OCC because in many applications, data update conflicts are rare because clients are naturally partitioned by business contexts to operate on different data. However, if your application chooses to use ETags, a request may get rejected because of mismatched ETags. It's recommended that you use a [retry policy](#Retry-Policies) to compensate for such conflicts when using ETags.
|
||||
Dapr chooses OCC because in many applications, data update conflicts are rare because clients are naturally partitioned by business contexts to operate on different data. However, if your application chooses to use ETags, a request may get rejected because of mismatched ETags. It's recommended that you use a [retry policy](#retry-policies) to compensate for such conflicts when using ETags.
|
||||
|
||||
If your application omits ETags in writing requests, Dapr skips ETag checks while handling the requests. This essentially enables the **last-write-wins** pattern, compared to the **first-write-wins** pattern with ETags.
|
||||
|
||||
> **NOTE:** For stores that don't natively support ETags, it's expected that the corresponding Dapr state store implementation simulates ETags and follows the Dapr state management API specification when handling states. Because Dapr state store implementations are technically clients to the underlying data store, such simulation should be straightforward using the concurrency control mechanisms provided by the store.
|
||||
{{% alert title="Note on ETags" color="primary" %}}
|
||||
For stores that don't natively support ETags, it's expected that the corresponding Dapr state store implementation simulates ETags and follows the Dapr state management API specification when handling states. Because Dapr state store implementations are technically clients to the underlying data store, such simulation should be straightforward using the concurrency control mechanisms provided by the store.
|
||||
{{% /alert %}}
|
||||
|
||||
### Consistency
|
||||
|
||||
|
@ -74,15 +69,21 @@ Dapr supports both **strong consistency** and **eventual consistency**, with eve
|
|||
|
||||
When strong consistency is used, Dapr waits for all replicas (or designated quorums) to acknowledge before it acknowledges a write request. When eventual consistency is used, Dapr returns as soon as the write request is accepted by the underlying data store, even if this is a single replica.
|
||||
|
||||
Visit the [API reference]({{< ref state_api.md >}}) to learn how to set consistency options.
|
||||
|
||||
### Retry policies
|
||||
|
||||
Dapr allows you to attach a retry policy to any write request. A policy is described by an **retryInterval**, a **retryPattern** and a **retryThreshold**. Dapr keeps retrying the request at the given interval up to the specified threshold. You can choose between a **linear** retry pattern or an **exponential** (backoff) pattern. When the **exponential** pattern is used, the retry interval is doubled after each attempt.
|
||||
|
||||
Visit the [API reference]({{< ref state_api.md >}}) to learn how to set retry policy options.
|
||||
|
||||
### Bulk operations
|
||||
|
||||
Dapr supports two types of bulk operations - **bulk** or **multi**. You can group several requests of the same type into a bulk (or a batch). Dapr submits requests in the bulk as individual requests to the underlying data store. In other words, bulk operations are not transactional. On the other hand, you can group requests of different types into a multi-operation, which is handled as an atomic transaction.
|
||||
|
||||
### Querying state store directly
|
||||
Visit the [API reference]({{< ref state_api.md >}}) to learn how use bulk and multi options.
|
||||
|
||||
### Query state store directly
|
||||
|
||||
Dapr saves and retrieves state values without any transformation. You can query and aggregate state directly from the [underlying state store]({{< ref query-state-store >}}).
|
||||
|
||||
|
@ -92,8 +93,6 @@ For example, to get all state keys associated with an application ID "myApp" in
|
|||
KEYS "myApp*"
|
||||
```
|
||||
|
||||
> **NOTE:** See [How to query Redis store]({{< ref query-redis-store.md >}} ) for details on how to query a Redis store.
|
||||
|
||||
#### Querying actor state
|
||||
|
||||
If the data store supports SQL queries, you can query an actor's state using SQL queries. For example use:
|
||||
|
@ -108,10 +107,12 @@ You can also perform aggregate queries across actor instances, avoiding the comm
|
|||
SELECT AVG(value) FROM StateTable WHERE Id LIKE '<app-id>||<thermometer>||*||temperature'
|
||||
```
|
||||
|
||||
> **NOTE:** Direct queries of the state store are not governed by Dapr concurrency control, since you are not calling through the Dapr runtime. What you see are snapshots of committed data which are acceptable for read-only queries across multiple actors, however writes should be done via the actor instances.
|
||||
{{% alert title="Note on direct queries" color="primary" %}}
|
||||
Direct queries of the state store are not governed by Dapr concurrency control, since you are not calling through the Dapr runtime. What you see are snapshots of committed data which are acceptable for read-only queries across multiple actors, however writes should be done via the actor instances.
|
||||
{{% /alert %}}
|
||||
|
||||
## Next steps
|
||||
|
||||
* Follow the [state store setup guides]({{< ref setup-state-store >}})
|
||||
* Read the [state management API specification]({{< ref state_api.md >}})
|
||||
* Read the [actors API specification]({{< ref actors_api.md >}})
|
||||
- Follow the [state store setup guides]({{< ref setup-state-store >}})
|
||||
- Read the [state management API specification]({{< ref state_api.md >}})
|
||||
- Read the [actors API specification]({{< ref actors_api.md >}})
|
||||
|
|
|
@ -1,22 +1,44 @@
|
|||
---
|
||||
type: docs
|
||||
title: "SDKs"
|
||||
title: "Dapr Software Development Kits (SDKs)"
|
||||
linkTitle: "SDKs"
|
||||
weight: 20
|
||||
description: "Use your favorite languages with Dapr"
|
||||
no_list: true
|
||||
---
|
||||
|
||||
### .NET
|
||||
See the [.NET SDK repository](https://github.com/dapr/dotnet-sdk)
|
||||
The Dapr SDKs are the easiest way for you to get Dapr into your application. Choose your favorite language and get up and running with Dapr in minutes.
|
||||
|
||||
### Java
|
||||
See the [Java SDK repository](https://github.com/dapr/java-sdk)
|
||||
## SDK packages
|
||||
|
||||
### Go
|
||||
See the [Go SDK repository](https://github.com/dapr/go-sdk)
|
||||
- **Client SDK**: The Dapr client allows you to invoke Dapr building block APIs and perform actions such as:
|
||||
- [Invoke]({{< ref service-invocation >}}) methods on other services
|
||||
- Store and get [state]({{< ref state-management >}})
|
||||
- [Publish and subscribe]({{< ref pubsub >}}) to message topics
|
||||
- Interact with external resources through input and output [bindings]({{< ref bindings >}})
|
||||
- Get [secrets]({{< ref secrets >}}) from secret stores
|
||||
- Interact with [virtual actors]({{< ref actors >}})
|
||||
- **Service extensions**: The Dapr service extensions allow you to create services that can:
|
||||
- Be [invoked]({{< ref service-invocation >}}) by other services
|
||||
- [Subscribe]({{< ref pubsub >}}) to topics
|
||||
- **Actor SDK**: The Dapr Actor SDK allows you to build virtual actors with:
|
||||
- Methods that can be [invoked]({{< ref "howto-actors.md#actor-method-invocation" >}}) by other services
|
||||
- [State]({{< ref "howto-actors.md#actor-state-management" >}}) that can be stored and retrieved
|
||||
- [Timers]({{< ref "howto-actors.md#actor-timers" >}}) with callbacks
|
||||
- Persistent [reminders]({{< ref "howto-actors.md#actor-reminders" >}})
|
||||
|
||||
### Python
|
||||
See the [Python SDK repository](https://github.com/dapr/python-sdk)
|
||||
## SDK languages
|
||||
|
||||
### Javascript
|
||||
See the [Javascript SDK repository](https://github.com/dapr/js-sdk)
|
||||
| Language | State | Client SDK | Service Extensions | Actor SDK |
|
||||
|----------|:-----:|:----------:|:-----------:|:---------:|
|
||||
| [.NET](https://github.com/dapr/dotnet-sdk) | In Development | ✔ | ASP.NET Core | ✔ |
|
||||
| [Python]({{< ref python >}}) | In Development | ✔ | [gRPC]({{< ref python-grpc.md >}}) | [FastAPI]({{< ref python-fastapi.md >}})<br />[Flask]({{< ref python-flask.md >}}) |
|
||||
| [Java](https://github.com/dapr/java-sdk) | In Development | ✔ | Spring Boot | ✔ |
|
||||
| [Go](https://github.com/dapr/go-sdk) | In Development | ✔ | ✔ | |
|
||||
| [C++](https://github.com/dapr/cpp-sdk) | Backlog | ✔ | |
|
||||
| [Rust]() | Backlog | ✔ | | |
|
||||
| [Javascript]() | Backlog | ✔ | |
|
||||
|
||||
## Further reading
|
||||
|
||||
- [Serialization in the Dapr SDKs]({{< ref sdk-serialization.md >}})
|
|
@ -2,7 +2,10 @@
|
|||
type: docs
|
||||
title: "Serialization in Dapr's SDKs"
|
||||
linkTitle: "Serialization"
|
||||
weight: 1000
|
||||
description: "How Dapr serializes data within the SDKs"
|
||||
weight: 2000
|
||||
aliases:
|
||||
- '/developing-applications/sdks/serialization/'
|
||||
---
|
||||
|
||||
An SDK for Dapr should provide serialization for two use cases. First, for API objects sent through request and response payloads. Second, for objects to be persisted. For both these use cases, a default serialization is provided. In the Java SDK, it is the [DefaultObjectSerializer](https://dapr.github.io/java-sdk/io/dapr/serializer/DefaultObjectSerializer.html) class, providing JSON serialization.
|
|
@ -0,0 +1,52 @@
|
|||
---
|
||||
type: docs
|
||||
title: "Component schema"
|
||||
linkTitle: "Component schema"
|
||||
weight: 100
|
||||
description: "The basic schema for a Dapr component"
|
||||
---
|
||||
|
||||
Dapr defines and registers components using a [CustomResourceDefinition](https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/). All components are defined as a CRD and can be applied to any hosting environment where Dapr is running, not just Kubernetes.
|
||||
|
||||
## Format
|
||||
|
||||
```yaml
|
||||
apiVersion: dapr.io/v1alpha1
|
||||
kind: Component
|
||||
metadata:
|
||||
name: [COMPONENT-NAME]
|
||||
namespace: [COMPONENT-NAMESPACE]
|
||||
spec:
|
||||
type: [COMPONENT-TYPE]
|
||||
version: v1
|
||||
initTimeout: [TIMEOUT-DURATION]
|
||||
ignoreErrors: [BOOLEAN]
|
||||
metadata:
|
||||
- name: [METADATA-NAME]
|
||||
value: [METADATA-VALUE]
|
||||
```
|
||||
|
||||
## Fields
|
||||
|
||||
| Field | Required | Details | Example |
|
||||
|--------------------|:--------:|---------|---------|
|
||||
| apiVersion | Y | The version of the Dapr (and Kubernetes if applicable) API you are calling | `dapr.io/v1alpha1`
|
||||
| kind | Y | The type of CRD. For components is must always be `Component` | `Component`
|
||||
| **metadata** | - | **Information about the component registration** |
|
||||
| metadata.name | Y | The name of the component | `prod-statestore`
|
||||
| metadata.namespace | N | The namespace for the component for hosting environments with namespaces | `myapp-namespace`
|
||||
| **spec** | - | **Detailed information on the component resource**
|
||||
| spec.type | Y | The type of the component | `state.redis`
|
||||
| spec.version | Y | The version of the component | `v1`
|
||||
| spec.initTimeout | N | The timeout duration for the initialization of the component. Default is 30s | `5m`, `1h`, `20s`
|
||||
| spec.ignoreErrors | N | Tells the Dapr sidecar to continue initialization if the component fails to load. Default is false | `false`
|
||||
| **spec.metadata** | - | **A key/value pair of component specific configuration. See your component definition for fields**|
|
||||
|
||||
## Further reading
|
||||
- [Components concept]({{< ref components-concept.md >}})
|
||||
- [Reference secrets in component definitions]({{< ref component-secrets.md >}})
|
||||
- [Supported state stores]({{< ref supported-state-stores >}})
|
||||
- [Supported pub/sub brokers]({{< ref supported-pubsub >}})
|
||||
- [Supported secret stores]({{< ref supported-secret-stores >}})
|
||||
- [Supported bindings]({{< ref supported-bindings >}})
|
||||
- [Set component scopes]({{< ref component-scopes.md >}})
|
|
@ -2,7 +2,7 @@
|
|||
type: docs
|
||||
title: "How-To: Scope components to one or more applications"
|
||||
linkTitle: "How-To: Set component scopes"
|
||||
weight: 100
|
||||
weight: 200
|
||||
description: "Limit component access to particular Dapr instances"
|
||||
---
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
type: docs
|
||||
title: "How-To: Reference secrets in components"
|
||||
linkTitle: "How-To: Reference secrets"
|
||||
weight: 200
|
||||
weight: 300
|
||||
description: "How to securly reference secrets from a component definition"
|
||||
---
|
||||
|
||||
|
|
|
@ -82,7 +82,7 @@ The most common cause of this failure is that a component (such as a state store
|
|||
|
||||
To diagnose the root cause:
|
||||
|
||||
- Significantly increase the liveness probe delay - [link]{{< ref "kubernetes-overview.md" >}})
|
||||
- Significantly increase the liveness probe delay - [link]({{< ref "kubernetes-overview.md" >}})
|
||||
- Set the log level of the sidecar to debug - [link]({{< ref "logs-troubleshooting.md#setting-the-sidecar-log-level" >}})
|
||||
- Watch the logs for meaningful information - [link]({{< ref "logs-troubleshooting.md#viewing-logs-on-kubernetes" >}})
|
||||
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 3d610a4db9a589d85de7fa20c42be1934a1d6f0e
|
Loading…
Reference in New Issue