Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F3769096
D992.id2549.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D992.id2549.diff
View Options
diff --git a/app.py b/app.py
--- a/app.py
+++ b/app.py
@@ -117,10 +117,15 @@
return str(uuid.uuid4())
+def get_queue_name(queue_key):
+ """Map a queue name with its key."""
+ return "delivery-" + queue_key
+
+
def add_broker_queue(exchange_name, routing_key):
"""Add a queue to the broker, bind to the exchange."""
queue_key = generate_queue_key()
- queue_name = "delivery-" + queue_key
+ queue_name = get_queue_name(queue_key)
connection = get_broker_connection(service['config'])
channel = connection.channel()
@@ -134,6 +139,13 @@
return queue_key
+def delete_broker_queue(queue_name, force_queue_deletion):
+ connection = get_broker_connection(service['config'])
+ channel = connection.channel()
+ channel.queue_delete(queue=queue_name, is_empty=not force_queue_deletion)
+ connection.close(reply_text="Operation done")
+
+
def get_variable_from_request(key, default_value=None):
"""Gets variable from request JSON payload or a default value."""
if key in request.json:
@@ -190,6 +202,26 @@
return jsonify(key=queue_key)
+@app.route(endpoint + "/unregister_consumer", methods=['POST'])
+def unregister_consumer():
+ """Unregister a queue key."""
+
+ # Reads request
+ if not request.json or "key" not in request.json:
+ abort(400)
+
+ queue = get_queue_name(request.json["key"])
+ force_delete = get_variable_from_request("force", False)
+
+ # Handles request
+ try:
+ delete_broker_queue(queue, force_delete)
+ return jsonify(key=queue, success=True,
+ result="Queue deletion request sent to the broker.")
+ except pika.exceptions.ChannelClosed as err:
+ return error_handler(err)
+
+
# -------------------------------------------------------------
# Start application
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 24, 12:58 (6 h, 49 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2260190
Default Alt Text
D992.id2549.diff (1 KB)
Attached To
Mode
D992: Implement /delivery/unregister_consumer API method
Attached
Detach File
Event Timeline
Log In to Comment