Skip to content

Commit 940c48b

Browse files
authored
Merge pull request #4403 from hhunter-ms/issue_4322
Update subscriptions examples
2 parents 2adc441 + 11215f6 commit 940c48b

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

daprdocs/content/en/developing-applications/building-blocks/pubsub/subscription-methods.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,16 @@ metadata:
3737
spec:
3838
topic: orders
3939
routes:
40-
default: /checkout
40+
default: /orders
4141
pubsubname: pubsub
4242
scopes:
4343
- orderprocessing
44-
- checkout
4544
```
4645
4746
Here the subscription called `order`:
4847
- Uses the pub/sub component called `pubsub` to subscribes to the topic called `orders`.
49-
- Sets the `route` field to send all topic messages to the `/checkout` endpoint in the app.
50-
- Sets `scopes` field to scope this subscription for access only by apps with IDs `orderprocessing` and `checkout`.
48+
- Sets the `route` field to send all topic messages to the `/orders` endpoint in the app.
49+
- Sets `scopes` field to scope this subscription for access only by apps with ID `orderprocessing`.
5150

5251
When running Dapr, set the YAML component file path to point Dapr to the component.
5352

@@ -113,7 +112,7 @@ In your application code, subscribe to the topic specified in the Dapr pub/sub c
113112

114113
```csharp
115114
//Subscribe to a topic
116-
[HttpPost("checkout")]
115+
[HttpPost("orders")]
117116
public void getCheckout([FromBody] int orderId)
118117
{
119118
Console.WriteLine("Subscriber received : " + orderId);
@@ -128,7 +127,7 @@ public void getCheckout([FromBody] int orderId)
128127
import io.dapr.client.domain.CloudEvent;
129128
130129
//Subscribe to a topic
131-
@PostMapping(path = "/checkout")
130+
@PostMapping(path = "/orders")
132131
public Mono<Void> getCheckout(@RequestBody(required = false) CloudEvent<String> cloudEvent) {
133132
return Mono.fromRunnable(() -> {
134133
try {
@@ -146,7 +145,7 @@ public Mono<Void> getCheckout(@RequestBody(required = false) CloudEvent<String>
146145
from cloudevents.sdk.event import v1
147146
148147
#Subscribe to a topic
149-
@app.route('/checkout', methods=['POST'])
148+
@app.route('/orders', methods=['POST'])
150149
def checkout(event: v1.Event) -> None:
151150
data = json.loads(event.Data())
152151
logging.info('Subscriber received: ' + str(data))
@@ -163,7 +162,7 @@ const app = express()
163162
app.use(bodyParser.json({ type: 'application/*+json' }));
164163
165164
// listen to the declarative route
166-
app.post('/checkout', (req, res) => {
165+
app.post('/orders', (req, res) => {
167166
console.log(req.body);
168167
res.sendStatus(200);
169168
});
@@ -178,7 +177,7 @@ app.post('/checkout', (req, res) => {
178177
var sub = &common.Subscription{
179178
PubsubName: "pubsub",
180179
Topic: "orders",
181-
Route: "/checkout",
180+
Route: "/orders",
182181
}
183182
184183
func eventHandler(ctx context.Context, e *common.TopicEvent) (retry bool, err error) {
@@ -191,7 +190,7 @@ func eventHandler(ctx context.Context, e *common.TopicEvent) (retry bool, err er
191190

192191
{{< /tabs >}}
193192

194-
The `/checkout` endpoint matches the `route` defined in the subscriptions and this is where Dapr sends all topic messages to.
193+
The `/orders` endpoint matches the `route` defined in the subscriptions and this is where Dapr sends all topic messages to.
195194

196195
### Streaming subscriptions
197196

@@ -325,7 +324,7 @@ In the example below, you define the values found in the [declarative YAML subsc
325324

326325
```csharp
327326
[Topic("pubsub", "orders")]
328-
[HttpPost("/checkout")]
327+
[HttpPost("/orders")]
329328
public async Task<ActionResult<Order>>Checkout(Order order, [FromServices] DaprClient daprClient)
330329
{
331330
// Logic
@@ -337,7 +336,7 @@ or
337336

338337
```csharp
339338
// Dapr subscription in [Topic] routes orders topic to this route
340-
app.MapPost("/checkout", [Topic("pubsub", "orders")] (Order order) => {
339+
app.MapPost("/orders", [Topic("pubsub", "orders")] (Order order) => {
341340
Console.WriteLine("Subscriber received : " + order);
342341
return Results.Ok(order);
343342
});
@@ -359,7 +358,7 @@ app.UseEndpoints(endpoints =>
359358
```java
360359
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
361360
362-
@Topic(name = "checkout", pubsubName = "pubsub")
361+
@Topic(name = "orders", pubsubName = "pubsub")
363362
@PostMapping(path = "/orders")
364363
public Mono<Void> handleMessage(@RequestBody(required = false) CloudEvent<String> cloudEvent) {
365364
return Mono.fromRunnable(() -> {
@@ -370,6 +369,7 @@ public Mono<Void> handleMessage(@RequestBody(required = false) CloudEvent<String
370369
throw new RuntimeException(e);
371370
}
372371
});
372+
}
373373
```
374374

375375
{{% /codetab %}}
@@ -382,7 +382,7 @@ def subscribe():
382382
subscriptions = [
383383
{
384384
'pubsubname': 'pubsub',
385-
'topic': 'checkout',
385+
'topic': 'orders',
386386
'routes': {
387387
'rules': [
388388
{
@@ -418,7 +418,7 @@ app.get('/dapr/subscribe', (req, res) => {
418418
res.json([
419419
{
420420
pubsubname: "pubsub",
421-
topic: "checkout",
421+
topic: "orders",
422422
routes: {
423423
rules: [
424424
{
@@ -480,7 +480,7 @@ func configureSubscribeHandler(w http.ResponseWriter, _ *http.Request) {
480480
t := []subscription{
481481
{
482482
PubsubName: "pubsub",
483-
Topic: "checkout",
483+
Topic: "orders",
484484
Routes: routes{
485485
Rules: []rule{
486486
{

0 commit comments

Comments
 (0)