Created
May 20, 2012 19:50
-
-
Save ifandelse/2759316 to your computer and use it in GitHub Desktop.
AMQP Style Bindings for postal.js
This file contains hidden or 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
| var amqpBindingsResolver = { | |
| cache : { }, | |
| compare : function ( binding, topic ) { | |
| if ( this.cache[topic] && this.cache[topic][binding] ) { | |
| return true; | |
| } | |
| // binding.replace(/\./g,"\\.") // escape actual periods | |
| // .replace(/#/g, ".*") // hashes match any value | |
| // .replace(/\*/g, "[A-Z,a-z,0-9]*"); // asterisks match any alpha-numeric 'word' | |
| var rgx = new RegExp( "^" + binding.replace( /\./g, "\\." ) | |
| .replace( /\*/g, "[A-Z,a-z,0-9]*" ) | |
| .replace( /#/g, ".*" ) + "$" ), | |
| result = rgx.test( topic ); | |
| if ( result ) { | |
| if ( !this.cache[topic] ) { | |
| this.cache[topic] = {}; | |
| } | |
| this.cache[topic][binding] = true; | |
| } | |
| return result; | |
| }, | |
| reset : function () { | |
| this.cache = {}; | |
| } | |
| }; | |
| // swap out postal's bindings with this one: | |
| postal.configuration.resolver = amqpBindingsResolver; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment