Created
May 11, 2012 11:25
-
-
Save inancsevinc/2659083 to your computer and use it in GitHub Desktop.
RabbitMq Json Definitions Generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>RabbitMq Json Definitions Generator</title> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> | |
<script type="text/javascript"> | |
$(function(){ | |
$('#generateBtn').on('click',function(){ | |
var generatedQueues = '' | |
,generatedBindings = '' | |
,queueName = $('#queueName').val() | |
,vhost = $('#vhost').val() | |
,queueCount = $('#queueCount').val() | |
,minTTL = $('#minTTL').val() | |
,deadLetterExchange = $('#deadLetterExchange').val() | |
,durable = $('#durable').val() | |
,autoDelete = $('#autoDelete').val() | |
,bindingSource = $('#bindingSource').val() | |
,bindingRoutingKey = $('#bindingRoutingKey').val(); | |
for(var i=1; i<queueCount; i++) { | |
generatedQueues = generatedQueues + '\n{\n'+ | |
'\t"name": "' +queueName+'_'+(i<10?'0'+i:i)+'",\n'+ | |
'\t"vhost": "/' +vhost+'",\n'+ | |
'\t"durable": ' +durable+',\n'+ | |
'\t"auto_delete": ' +autoDelete+',\n'+ | |
'\t"arguments": {\n'+ | |
'\t\t"x-message-ttl": '+minTTL*i+',\n'+ | |
'\t\t"x-dead-letter-exchange": "'+deadLetterExchange+'"\n\t}'+ | |
'\n},'; | |
generatedBindings = generatedBindings + '\n{\n'+ | |
'\t"source": "' +bindingSource+'",\n'+ | |
'\t"vhost": "/' +vhost+'",\n'+ | |
'\t"destination": "' +queueName+'_'+(i<10?'0'+i:i)+'",\n'+ | |
'\t"destination_type": "queue",\n'+ | |
'\t"routing_key": "'+bindingRoutingKey.replace('?',i)+'",\n'+ | |
'\t"arguments": {}'+ | |
'\n},'; | |
} | |
$('#generatedJson').text('Queues:\n'+generatedQueues+'\n\nBindings:\n'+generatedBindings); | |
}); | |
$('#ttlMultiplyBtn').on('click',function(){ | |
var sourceJson = $('#sourceJson').val() | |
,ttlMultiplier = $('#ttlMultiplier').val() | |
,replacedJson = sourceJson.replace(/("x-message-ttl": )(\d+)(,)/g, function($0,$1,$2,$3){ return $1+($2*ttlMultiplier)+$3} ); | |
$('#sourceJson').val(replacedJson); | |
}); | |
}); | |
</script> | |
</head> | |
<body> | |
<h2>Generate Queues/Bindings</h2> | |
<div>Vhost: /<input type="text" id="vhost" value="pikzminder"/></div> | |
<div>QueueName: <input type="text" id="queueName" value="q_min"/></div> | |
<div>QueueCount: <input type="text" id="queueCount" value="60"/></div> | |
<div>MinTTL: <input type="text" id="minTTL" value="1000"/></div> | |
<div>DeadLetterExchange: <input type="text" id="deadLetterExchange" value="e_job"/></div> | |
<div>Durable: | |
<select id="durable"> | |
<option value="true">true</option> | |
<option value="false">false </option> | |
</select> | |
</div> | |
<div>AutoDelete: | |
<select id="autoDelete"> | |
<option value="false">false</option> | |
<option value="true">true</option> | |
</select> | |
</div> | |
<div>SourceExchange: <input type="text" id="bindingSource" value="e_min"/></div> | |
<div>RoutingKey: <input type="text" id="bindingRoutingKey" value="*.*.*.*.?"/></div> | |
<button id="generateBtn" >Generate</button> | |
<div> | |
<textarea id="sourceJson" cols="100" rows="20"></textarea> | |
</div> | |
<div> | |
TTLMultiplier: <input type="text" id="ttlMultiplier" /> | |
</div> | |
<button id="ttlMultiplyBtn" >Change TTL Values</button> | |
<pre id="generatedJson"></pre> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment