Skip to content

Commit

Permalink
Update daprdocs/content/en/developing-applications/building-blocks/pu…
Browse files Browse the repository at this point in the history
…bsub/pubsub-bulk.md

Co-authored-by: Elena Kolevska <[email protected]>
Signed-off-by: Hannah Hunter <[email protected]>
  • Loading branch information
hhunter-ms and elena-kolevska authored Nov 14, 2024
1 parent 6f47d2c commit a7e578a
Showing 1 changed file with 20 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -474,49 +474,40 @@ public class BulkMessageController : ControllerBase
Currently, you can only bulk subscribe in Python using an HTTP client.

```python
import requests
import json
from flask import Flask, request, jsonify
# Define the Dapr sidecar URL
DAPR_URL = "http://localhost:3500/v1.0"
# Define the subscription endpoint
SUBSCRIBE_URL = f"{DAPR_URL}/subscribe"
# Define the bulk subscribe configuration
subscription = {
"pubsubname": "order-pub-sub",
"topic": "orders",
"route": "/checkout",
"bulkSubscribe": {
"enabled": True,
"maxMessagesCount": 100,
"maxAwaitDurationMs": 40
}
}
app = Flask(__name__)
# Send the subscription request
response = requests.post(SUBSCRIBE_URL, json=subscription)
@app.route('/dapr/subscribe', methods=['GET'])
def subscribe():
# Define the bulk subscribe configuration
subscriptions = [{
"pubsubname": "pubsub",
"topic": "TOPIC_A",
"route": "/checkout",
"bulkSubscribe": {
"enabled": True,
"maxMessagesCount": 3,
"maxAwaitDurationMs": 40
}
}]
print('Dapr pub/sub is subscribed to: ' + json.dumps(subscriptions))
return jsonify(subscriptions)
if response.status_code == 200:
print("Bulk subscription created successfully!")
else:
print(f"Failed to create bulk subscription: {response.status_code} - {response.text}")
# Define the endpoint to handle incoming messages
from flask import Flask, request
app = Flask(__name__)
@app.route('/checkout', methods=['POST'])
def checkout():
messages = request.json
print(messages)
for message in messages:
print(f"Received message: {message}")
return '', 200
return json.dumps({'success': True}), 200, {'ContentType': 'application/json'}
if __name__ == '__main__':
app.run(port=5000)
```

{{% /codetab %}}
Expand Down

0 comments on commit a7e578a

Please sign in to comment.