Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add elements to json for bindings to default exchange #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion rabbitmq_graphviz.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#! /usr/bin/python


import argparse
import json
import sys
Expand All @@ -10,6 +13,25 @@ def build_definitions(definitions, vhost, render_producers, render_consumers):
def is_same_vhost(entity_dict):
return entity_dict['vhost'] == vhost

# If there's a queue but no binding, add a default binding
# (to the "" exchange with the queue name as the routing key)
# That's the normal way a message would get into that queue.
for queue in definitions['queues']:
if not [i for i in definitions['bindings'] if i['destination'] == queue['name'] ]:
definitions['bindings'].append({'vhost': queue['vhost'], 'destination': queue['name'],
'routing_key': queue['name'], 'source': 'NULL',
'arguments': {}, 'destination_type': 'queue'}
)

# if there is now a binding but no exchange in that vhost that matches, create the exchange
for binding in definitions['bindings']:
if not [ e for e in definitions['exchanges']
if e['name'] == binding['source'] and e['vhost'] == binding['vhost'] ]:
definitions['exchanges'].append({'name':binding['source'], 'durable' : True,
'vhost':binding['vhost'],'internal':True, 'arguments':{},
'type':'direct','auto_delete':False}
)

return ''.join([
'digraph {\n',
' bgcolor=transparent;\n',
Expand Down Expand Up @@ -77,6 +99,6 @@ def parse_args():

definitions = json.load(args.definitions)
args.definitions.close()

args.outfile.write(build_definitions(definitions, args.vhost, args.producers, args.consumers))
args.outfile.close()