Update daprdocs/content/en/developing-applications/building-blocks/pubsub/pubsub-bulk.md

Co-authored-by: Elena Kolevska <elena-kolevska@users.noreply.github.com>
Signed-off-by: Hannah Hunter <94493363+hhunter-ms@users.noreply.github.com>
This commit is contained in:
Hannah Hunter 2024-11-14 12:13:23 -05:00 committed by GitHub
parent 6f47d2c748
commit a7e578aae4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 22 additions and 31 deletions

View File

@ -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
# 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
}
}
# Send the subscription request
response = requests.post(SUBSCRIBE_URL, json=subscription)
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
from flask import Flask, request, jsonify
app = Flask(__name__)
@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)
# Define the endpoint to handle incoming messages
@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 %}}