@@ -336,14 +336,13 @@ Status | Description
336
336
` RETRY` | Message to be retried by Dapr
337
337
` DROP` | Warning is logged and message is dropped
338
338
339
- Please refer [Expected HTTP Response for Bulk Subscribe]({{< ref pubsub_api.md >}}) for further insights on response.
339
+ Refer to [Expected HTTP Response for Bulk Subscribe]({{< ref pubsub_api.md >}}) for further insights on response.
340
340
341
341
# ## Example
342
342
343
- Please refer following code samples for how to use Bulk Subscribe :
344
-
345
- {{< tabs "Java" "JavaScript" ".NET" >}}
343
+ The following code examples demonstrate how to use Bulk Subscribe.
346
344
345
+ {{< tabs "Java" "JavaScript" ".NET" "Python" >}}
347
346
{{% codetab %}}
348
347
349
348
` ` ` java
@@ -471,7 +470,50 @@ public class BulkMessageController : ControllerBase
471
470
472
471
{{% /codetab %}}
473
472
473
+ {{% codetab %}}
474
+ Currently, you can only bulk subscribe in Python using an HTTP client.
475
+
476
+ ` ` ` python
477
+ import json
478
+ from flask import Flask, request, jsonify
479
+
480
+ app = Flask(__name__)
481
+
482
+ @app.route('/dapr/subscribe', methods=['GET'])
483
+ def subscribe():
484
+ # Define the bulk subscribe configuration
485
+ subscriptions = [{
486
+ "pubsubname": "pubsub",
487
+ "topic": "TOPIC_A",
488
+ "route": "/checkout",
489
+ "bulkSubscribe": {
490
+ "enabled": True,
491
+ "maxMessagesCount": 3,
492
+ "maxAwaitDurationMs": 40
493
+ }
494
+ }]
495
+ print('Dapr pub/sub is subscribed to: ' + json.dumps(subscriptions))
496
+ return jsonify(subscriptions)
497
+
498
+
499
+ # Define the endpoint to handle incoming messages
500
+ @app.route('/checkout', methods=['POST'])
501
+ def checkout():
502
+ messages = request.json
503
+ print(messages)
504
+ for message in messages:
505
+ print(f"Received message: {message}")
506
+ return json.dumps({'success': True}), 200, {'ContentType': 'application/json'}
507
+
508
+ if __name__ == '__main__':
509
+ app.run(port=5000)
510
+
511
+ ` ` `
512
+
513
+ {{% /codetab %}}
514
+
474
515
{{< /tabs >}}
516
+
475
517
# # How components handle publishing and subscribing to bulk messages
476
518
477
519
For event publish/subscribe, two kinds of network transfers are involved.
0 commit comments