1
1
var events = require ( 'events' ) ,
2
2
sys = require ( 'sys' ) ,
3
3
net = require ( 'net' ) ,
4
- protocol = require ( './amqp-definitions-0-8' ) ,
4
+ protocol ,
5
5
Buffer = require ( 'buffer' ) . Buffer ,
6
6
Promise = require ( './promise' ) . Promise ;
7
7
@@ -80,32 +80,6 @@ var methods = {};
80
80
// classes keyed on their index
81
81
var classes = { } ;
82
82
83
- ( function ( ) { // anon scope for init
84
- //debug("initializing amqp methods...");
85
- for ( var i = 0 ; i < protocol . classes . length ; i ++ ) {
86
- var classInfo = protocol . classes [ i ] ;
87
- classes [ classInfo . index ] = classInfo ;
88
- for ( var j = 0 ; j < classInfo . methods . length ; j ++ ) {
89
- var methodInfo = classInfo . methods [ j ] ;
90
-
91
- var name = classInfo . name
92
- + methodInfo . name [ 0 ] . toUpperCase ( )
93
- + methodInfo . name . slice ( 1 ) ;
94
- //debug(name);
95
-
96
- var method = { name : name
97
- , fields : methodInfo . fields
98
- , methodIndex : methodInfo . index
99
- , classIndex : classInfo . index
100
- } ;
101
-
102
- if ( ! methodTable [ classInfo . index ] ) methodTable [ classInfo . index ] = { } ;
103
- methodTable [ classInfo . index ] [ methodInfo . index ] = method ;
104
- methods [ name ] = method ;
105
- }
106
- }
107
- } ) ( ) ; // end anon scope
108
-
109
83
110
84
111
85
// parser
@@ -117,7 +91,7 @@ var maxFrameBuffer = 131072; // same as rabbitmq
117
91
// An interruptible AMQP parser.
118
92
//
119
93
// type is either 'server' or 'client'
120
- // version is '0-8' or '0- 9-1'. Currently only supporting '0-8 '.
94
+ // version is '0-9-1'.
121
95
//
122
96
// Instances of this class have several callbacks
123
97
// - onMethod(channel, method, args);
@@ -132,7 +106,35 @@ function AMQPParser (version, type) {
132
106
this . isClient = ( type == 'client' ) ;
133
107
this . state = this . isClient ? 'frameHeader' : 'protocolHeader' ;
134
108
135
- if ( version != '0-8' ) throw new Error ( "Unsupported protocol version" ) ;
109
+ if ( version != '0-9-1' ) throw new Error ( "Unsupported protocol version" ) ;
110
+
111
+ protocol = require ( './amqp-definitions-' + version ) ;
112
+
113
+ ( function ( ) { // anon scope for init
114
+ //debug("initializing amqp methods...");
115
+ for ( var i = 0 ; i < protocol . classes . length ; i ++ ) {
116
+ var classInfo = protocol . classes [ i ] ;
117
+ classes [ classInfo . index ] = classInfo ;
118
+ for ( var j = 0 ; j < classInfo . methods . length ; j ++ ) {
119
+ var methodInfo = classInfo . methods [ j ] ;
120
+
121
+ var name = classInfo . name
122
+ + methodInfo . name [ 0 ] . toUpperCase ( )
123
+ + methodInfo . name . slice ( 1 ) ;
124
+ //debug(name);
125
+
126
+ var method = { name : name
127
+ , fields : methodInfo . fields
128
+ , methodIndex : methodInfo . index
129
+ , classIndex : classInfo . index
130
+ } ;
131
+
132
+ if ( ! methodTable [ classInfo . index ] ) methodTable [ classInfo . index ] = { } ;
133
+ methodTable [ classInfo . index ] [ methodInfo . index ] = method ;
134
+ methods [ name ] = method ;
135
+ }
136
+ }
137
+ } ) ( ) ; // end anon scope
136
138
137
139
this . frameHeader = new Buffer ( 7 ) ;
138
140
this . frameHeader . used = 0 ;
@@ -619,7 +621,7 @@ function serializeFields (buffer, fields, args, strict) {
619
621
buffer [ buffer . used ++ ] = bitField ;
620
622
bitField = 0 ;
621
623
bitIndex = 0 ;
622
- }
624
+ }
623
625
break ;
624
626
625
627
case 'octet' :
@@ -692,7 +694,7 @@ function Connection (options) {
692
694
self . queues = { } ;
693
695
self . exchanges = { } ;
694
696
695
- parser = new AMQPParser ( '0-8 ' , 'client' ) ;
697
+ parser = new AMQPParser ( '0-9-1 ' , 'client' ) ;
696
698
697
699
parser . onMethod = function ( channel , method , args ) {
698
700
self . _onMethod ( channel , method , args ) ;
@@ -723,7 +725,7 @@ function Connection (options) {
723
725
//debug("connected...");
724
726
// Time to start the AMQP 7-way connection initialization handshake!
725
727
// 1. The client sends the server a version string
726
- self . write ( "AMQP" + String . fromCharCode ( 1 , 1 , 8 , 0 ) ) ;
728
+ self . write ( "AMQP" + String . fromCharCode ( 0 , 0 , 9 , 1 ) ) ;
727
729
state = 'handshake' ;
728
730
} ) ;
729
731
@@ -791,8 +793,8 @@ Connection.prototype._onMethod = function (channel, method, args) {
791
793
// 2. The server responds, after the version string, with the
792
794
// 'connectionStart' method (contains various useless information)
793
795
case methods . connectionStart :
794
- // We check that they're serving us AMQP 0-8
795
- if ( args . versionMajor != 8 && args . versionMinor != 0 ) {
796
+ // We check that they're serving us AMQP 0-9
797
+ if ( args . versionMajor != 0 && args . versionMinor != 9 ) {
796
798
this . end ( ) ;
797
799
this . emit ( 'error' , new Error ( "Bad server version" ) ) ;
798
800
return ;
@@ -825,8 +827,10 @@ Connection.prototype._onMethod = function (channel, method, args) {
825
827
// 6. Then we have to send a connectionOpen request
826
828
this . _sendMethod ( 0 , methods . connectionOpen ,
827
829
{ virtualHost : this . options . vhost
828
- , capabilities : ''
829
- , insist : true
830
+ // , capabilities: ''
831
+ // , insist: true
832
+ , reserved1 : ''
833
+ , reserved2 : true
830
834
} ) ;
831
835
break ;
832
836
@@ -1140,7 +1144,7 @@ function Channel (connection, channel) {
1140
1144
this . connection = connection ;
1141
1145
this . _tasks = [ ] ;
1142
1146
1143
- this . connection . _sendMethod ( channel , methods . channelOpen , { outOfBand : "" } ) ;
1147
+ this . connection . _sendMethod ( channel , methods . channelOpen , { reserved1 : "" } ) ;
1144
1148
}
1145
1149
sys . inherits ( Channel , events . EventEmitter ) ;
1146
1150
@@ -1212,13 +1216,13 @@ Queue.prototype.subscribeRaw = function (/* options, messageListener */) {
1212
1216
1213
1217
return this . _taskPush ( methods . basicConsumeOk , function ( ) {
1214
1218
self . connection . _sendMethod ( self . channel , methods . basicConsume ,
1215
- { ticket : 0
1219
+ { reserved1 : 0
1216
1220
, queue : self . name
1217
1221
, consumerTag : "."
1218
1222
, noLocal : options . noLocal ? true : false
1219
1223
, noAck : options . noAck ? true : false
1220
1224
, exclusive : options . exclusive ? true : false
1221
- , nowait : false
1225
+ , noWait : false
1222
1226
, "arguments" : { }
1223
1227
} ) ;
1224
1228
} ) ;
@@ -1306,31 +1310,62 @@ Queue.prototype.bind = function (/* [exchange,] routingKey */) {
1306
1310
// The first argument, exchange is optional.
1307
1311
// If not supplied the connection will use the default 'amq.topic'
1308
1312
// exchange.
1309
-
1313
+
1310
1314
var exchange , routingKey ;
1311
1315
1312
1316
if ( arguments . length == 2 ) {
1313
1317
exchange = arguments [ 0 ] ;
1314
1318
routingKey = arguments [ 1 ] ;
1315
1319
} else {
1316
- exchange = 'amq.topic' ;
1320
+ exchange = 'amq.topic' ;
1317
1321
routingKey = arguments [ 0 ] ;
1318
1322
}
1319
1323
1320
1324
1321
1325
return this . _taskPush ( methods . queueBindOk , function ( ) {
1322
1326
var exchangeName = exchange instanceof Exchange ? exchange . name : exchange ;
1323
1327
self . connection . _sendMethod ( self . channel , methods . queueBind ,
1324
- { ticket : 0
1328
+ { reserved1 : 0
1325
1329
, queue : self . name
1326
1330
, exchange : exchangeName
1327
1331
, routingKey : routingKey
1328
- , nowait : false
1332
+ , noWait : false
1329
1333
, "arguments" : { }
1330
1334
} ) ;
1331
1335
} ) ;
1332
1336
} ;
1333
1337
1338
+ Queue . prototype . bind_headers = function ( /* [exchange,] matchingPairs */ ) {
1339
+ var self = this ;
1340
+
1341
+ // The first argument, exchange is optional.
1342
+ // If not supplied the connection will use the default 'amq.headers'
1343
+ // exchange.
1344
+
1345
+ var exchange , matchingPairs ;
1346
+
1347
+ if ( arguments . length == 2 ) {
1348
+ exchange = arguments [ 0 ] ;
1349
+ matchingPairs = arguments [ 1 ] ;
1350
+ } else {
1351
+ exchange = 'amq.headers' ;
1352
+ matchingPairs = arguments [ 0 ] ;
1353
+ }
1354
+
1355
+
1356
+ return this . _taskPush ( methods . queueBindOk , function ( ) {
1357
+ var exchangeName = exchange instanceof Exchange ? exchange . name : exchange ;
1358
+ self . connection . _sendMethod ( self . channel , methods . queueBind ,
1359
+ { reserved1 : 0
1360
+ , queue : self . name
1361
+ , exchange : exchangeName
1362
+ , routingKey : ''
1363
+ , noWait : false
1364
+ , "arguments" : matchingPairs
1365
+ } ) ;
1366
+ } ) ;
1367
+ } ;
1368
+
1334
1369
1335
1370
Queue . prototype . destroy = function ( options ) {
1336
1371
var self = this ;
@@ -1354,13 +1389,13 @@ Queue.prototype._onMethod = function (channel, method, args) {
1354
1389
switch ( method ) {
1355
1390
case methods . channelOpenOk :
1356
1391
this . connection . _sendMethod ( channel , methods . queueDeclare ,
1357
- { ticket : 0
1392
+ { reserved1 : 0
1358
1393
, queue : this . name
1359
1394
, passive : this . options . passive ? true : false
1360
1395
, durable : this . options . durable ? true : false
1361
1396
, exclusive : this . options . exclusive ? true : false
1362
1397
, autoDelete : this . options . autoDelete ? true : false
1363
- , nowait : false
1398
+ , noWait : false
1364
1399
, "arguments" : { }
1365
1400
} ) ;
1366
1401
this . state = "declare queue" ;
@@ -1516,7 +1551,7 @@ Exchange.prototype.publish = function (routingKey, data, options) {
1516
1551
var self = this ;
1517
1552
return this . _taskPush ( null , function ( ) {
1518
1553
self . connection . _sendMethod ( self . channel , methods . basicPublish ,
1519
- { ticket : 0
1554
+ { reserved1 : 0
1520
1555
, exchange : self . name
1521
1556
, routingKey : routingKey
1522
1557
, mandatory : options . mandatory ? true : false
0 commit comments