mirror of https://github.com/dapr/docs.git
update code snippets
Signed-off-by: Hannah Hunter <hannahhunter@microsoft.com>
This commit is contained in:
parent
b2d97e13f9
commit
3cf224f8ec
|
|
@ -104,7 +104,6 @@ In your application code, subscribe to the topic specified in the Dapr pub/sub c
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
//Subscribe to a topic
|
//Subscribe to a topic
|
||||||
[Topic("pubsub", "orders")]
|
|
||||||
[HttpPost("checkout")]
|
[HttpPost("checkout")]
|
||||||
public void getCheckout([FromBody] int orderId)
|
public void getCheckout([FromBody] int orderId)
|
||||||
{
|
{
|
||||||
|
|
@ -117,16 +116,15 @@ public void getCheckout([FromBody] int orderId)
|
||||||
{{% codetab %}}
|
{{% codetab %}}
|
||||||
|
|
||||||
```java
|
```java
|
||||||
|
import io.dapr.client.domain.CloudEvent;
|
||||||
|
|
||||||
//Subscribe to a topic
|
//Subscribe to a topic
|
||||||
@Topic(name = "orders", pubsubName = "pubsub")
|
|
||||||
@PostMapping(path = "/checkout")
|
@PostMapping(path = "/checkout")
|
||||||
public Mono<Void> getCheckout(@RequestBody(required = false) CloudEvent<String> cloudEvent) {
|
public Mono<Void> getCheckout(@RequestBody(required = false) CloudEvent<String> cloudEvent) {
|
||||||
return Mono.fromRunnable(() -> {
|
return Mono.fromRunnable(() -> {
|
||||||
try {
|
try {
|
||||||
log.info("Subscriber received: " + cloudEvent.getData());
|
log.info("Subscriber received: " + cloudEvent.getData());
|
||||||
} catch (Exception e) {
|
}
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
@ -150,11 +148,16 @@ def checkout(event: v1.Event) -> None:
|
||||||
{{% codetab %}}
|
{{% codetab %}}
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
//Subscribe to a topic
|
const express = require('express')
|
||||||
await server.pubsub.subscribe("pubsub", "orders", "checkout", async (orderId) => {
|
const bodyParser = require('body-parser')
|
||||||
console.log(`Subscriber received: ${JSON.stringify(orderId)}`)
|
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 %}}
|
{{% /codetab %}}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue