Merge branch 'v1.9' into resiliency_quickstart

This commit is contained in:
Hannah Hunter 2022-11-11 10:04:30 -06:00 committed by GitHub
commit fc6fc9ffc1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 74 additions and 20 deletions

View File

@ -104,7 +104,6 @@ In your application code, subscribe to the topic specified in the Dapr pub/sub c
```csharp
//Subscribe to a topic
[Topic("pubsub", "orders")]
[HttpPost("checkout")]
public void getCheckout([FromBody] int orderId)
{
@ -117,16 +116,15 @@ public void getCheckout([FromBody] int orderId)
{{% codetab %}}
```java
import io.dapr.client.domain.CloudEvent;
//Subscribe to a topic
@Topic(name = "orders", pubsubName = "pubsub")
@PostMapping(path = "/checkout")
public Mono<Void> getCheckout(@RequestBody(required = false) CloudEvent<String> cloudEvent) {
return Mono.fromRunnable(() -> {
try {
log.info("Subscriber received: " + cloudEvent.getData());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
});
}
```
@ -136,13 +134,13 @@ public Mono<Void> getCheckout(@RequestBody(required = false) CloudEvent<String>
{{% codetab %}}
```python
from cloudevents.sdk.event import v1
#Subscribe to a topic
@app.subscribe(pubsub_name='pubsub', topic='orders')
def mytopic(event: v1.Event) -> None:
@app.route('/checkout', methods=['POST'])
def checkout(event: v1.Event) -> None:
data = json.loads(event.Data())
logging.info('Subscriber received: ' + str(data))
app.run(6002)
```
{{% /codetab %}}
@ -150,11 +148,16 @@ app.run(6002)
{{% codetab %}}
```javascript
//Subscribe to a topic
await server.pubsub.subscribe("pubsub", "orders", async (orderId) => {
console.log(`Subscriber received: ${JSON.stringify(orderId)}`)
const express = require('express')
const bodyParser = require('body-parser')
const app = express()
app.use(bodyParser.json({ type: 'application/*+json' }));
// listen to the declarative route
app.post('/checkout', (req, res) => {
console.log(req.body);
res.sendStatus(200);
});
await server.startServer();
```
{{% /codetab %}}
@ -163,11 +166,10 @@ await server.startServer();
```go
//Subscribe to a topic
if err := s.AddTopicEventHandler(sub, eventHandler); err != nil {
log.Fatalf("error adding topic subscription: %v", err)
}
if err := s.Start(); err != nil && err != http.ErrServerClosed {
log.Fatalf("error listenning: %v", err)
var sub = &common.Subscription{
PubsubName: "pubsub",
Topic: "orders",
Route: "/checkout",
}
func eventHandler(ctx context.Context, e *common.TopicEvent) (retry bool, err error) {

View File

@ -66,10 +66,14 @@ The above example uses secrets as plain strings. It is recommended to use a secr
This component supports **output binding** with the following operations:
- `create`
- `get`
- `delete`
### create
You can store a record in Redis using the `create` operation. This sets a key to hold a value. If the key already exists, the value is overwritten.
### Request
#### Request
```json
{
@ -84,10 +88,58 @@ You can store a record in Redis using the `create` operation. This sets a key to
}
```
### Response
#### Response
An HTTP 204 (No Content) and empty body is returned if successful.
### get
You can get a record in Redis using the `get` operation. This gets a key that was previously set.
#### Request
```json
{
"operation": "get",
"metadata": {
"key": "key1"
},
"data": {
}
}
```
#### Response
```json
{
"data": {
"Hello": "World",
"Lorem": "Ipsum"
}
}
```
### delete
You can delete a record in Redis using the `delete` operation. Returns success whether the key exists or not.
#### Request
```json
{
"operation": "delete",
"metadata": {
"key": "key1"
}
}
```
#### Response
An HTTP 204 (No Content) and empty body is returned if successful.
## Create a Redis instance
Dapr can use any Redis instance - containerized, running on your local dev machine, or a managed cloud service, provided the version of Redis is 5.0.0 or later.