Permalink
Browse files

Support exchange-to-exchange binding

* Added two methods to Exchange for binding and unbinding exchanges.
* Added method definitions for those methods.
  • Loading branch information...
1 parent 4856379 commit dedc12683619a9757ad305a872aa274fed561eb8 Son Tran-Nguyen committed with Son Tran-Nguyen Oct 2, 2012
Showing with 48 additions and 1 deletion.
  1. +1 −1 amqp-definitions-0-9-1.js
  2. +47 −0 amqp.js

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
47 amqp.js
@@ -2074,6 +2074,15 @@ Exchange.prototype._onMethod = function (channel, method, args) {
break;
+ case methods.exchangeBindOk:
+ if (this._bindCallback) {
+ // setting this._bindCallback to null before calling the callback allows for a subsequent bind within the callback
+ var cb = this._bindCallback;
+ this._bindCallback = null;
+ cb(this);
+ }
+ break;
+
case methods.confirmSelectOk:
this._sequence = 1;
@@ -2137,6 +2146,44 @@ Exchange.prototype._onMethod = function (channel, method, args) {
this._tasksFlush();
};
+Exchange.prototype.bind = function (exchange, routingKey, callback) {
+ var self = this;
+
+ if(callback) this._bindCallback = callback;
+
+ var exchangeName = exchange instanceof Exchange ? exchange.name : exchange;
+
+ if(exchangeName in self.connection.exchanges) {
+ this.exchange = self.connection.exchanges[exchangeName];
+ this.exchange.binds++;
+ }
+
+ self.connection._sendMethod(self.channel, methods.exchangeBind,
+ { reserved1: 0
+ , destination: self.name
+ , source: exchangeName
+ , routingKey: routingKey
+ , noWait: false
+ , "arguments": {}
+ });
+
+};
+
+Exchange.prototype.unbind = function (exchange, routingKey) {
+ var self = this;
+
+ return this._taskPush(methods.exchangeUnbindOk, function () {
+ var exchangeName = exchange instanceof Exchange ? exchange.name : exchange;
+ self.connection._sendMethod(self.channel, methods.exchangeUnbind,
+ { reserved1: 0
+ , destination: self.name
+ , source: exchangeName
+ , routingKey: routingKey
+ , noWait: false
+ , "arguments": {}
+ });
+ });
+};
// exchange.publish('routing.key', 'body');
//

0 comments on commit dedc126

Please sign in to comment.