Skip to content

Instantly share code, notes, and snippets.

@ifandelse
Created May 20, 2012 19:50
Show Gist options
  • Select an option

  • Save ifandelse/2759316 to your computer and use it in GitHub Desktop.

Select an option

Save ifandelse/2759316 to your computer and use it in GitHub Desktop.
AMQP Style Bindings for postal.js
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