20
20
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
21
21
*/
22
22
23
+ // ## stomp
24
+ //
25
+ // The `Stomp` module provides you with a client interface for interacting with STOMP messaging brokers
26
+ //
27
+ // ### stomp.Stomp
28
+ //
29
+ // An instance of the `Stomp` object. Initialized like so:
30
+ //
31
+ // var stomp_args = {
32
+ // port: 61613,
33
+ // host: 'localhost',
34
+ // debug: false,
35
+ // login: 'guest',
36
+ // passcode: 'guest',
37
+ // };
38
+ //
39
+ // var client = new stomp.Stomp(stomp_args);
40
+ //
41
+ // If debug is set to true, extra output will be printed to the console.
42
+
23
43
var net = require ( 'net' ) ,
24
44
tls = require ( 'tls' ) ,
25
45
sys = require ( 'util' ) ,
@@ -29,6 +49,8 @@ var net = require('net'),
29
49
utils = new stomp_utils . StompUtils ( ) ,
30
50
log = null ;
31
51
52
+ // ## Helpers to handle frames, and do parsing
53
+
32
54
function parse_command ( data ) {
33
55
var command ,
34
56
this_string = data . toString ( 'utf8' , 0 , data . length ) ;
@@ -231,10 +253,11 @@ function send_frame(stomp, _frame) {
231
253
return true ;
232
254
} ;
233
255
234
- /**
235
- * Stomp - Client API
236
- * @param {Object } args
237
- */
256
+ //
257
+ // ## Stomp - Client API
258
+ //
259
+ // Takes an argument object
260
+ //
238
261
function Stomp ( args ) {
239
262
this . port = args [ 'port' ] || 61613 ;
240
263
this . host = args [ 'host' ] || "127.0.0.1" ;
@@ -252,22 +275,24 @@ function Stomp(args) {
252
275
253
276
Stomp . prototype = new process . EventEmitter ( ) ;
254
277
255
- /**
256
- * Begin connection
257
- */
278
+ // ## Stomp.connect()
279
+ //
280
+ // **Begin connection**
281
+ //
258
282
Stomp . prototype . connect = function ( ) {
259
283
_connect ( this ) ;
260
284
} ;
261
285
262
- /**
263
- * Handle frame based on type
264
- * @param {Object } Frame Object
265
- */
286
+ // ## Stomp.handle\_new_frame()
287
+ //
288
+ // **Handle frame based on type**
289
+ //
290
+ // Takes a `Frame` object
291
+ //
266
292
Stomp . prototype . handle_new_frame = function ( this_frame ) {
267
293
switch ( this_frame . command ) {
268
294
case "MESSAGE" :
269
295
if ( utils . really_defined ( this_frame . headers [ 'message-id' ] ) ) {
270
- // if a subscription to the destination queue exists, fire callback
271
296
if ( this_frame . headers !== null && this_frame . headers . destination !== null && this . _subscribed_to [ this_frame . headers . destination ] !== null ) {
272
297
var subscription = this . _subscribed_to [ this_frame . headers . destination ] ;
273
298
if ( subscription . enabled && subscription . callback !== null && typeof ( subscription . callback ) == 'function' ) {
@@ -294,17 +319,24 @@ Stomp.prototype.handle_new_frame = function(this_frame) {
294
319
}
295
320
} ;
296
321
297
- /**
298
- * Disconnect from STOMP broker
299
- */
322
+ //
323
+ // ## `Stomp.disconnect()`
324
+ //
325
+ // **Disconnect from STOMP broker**
326
+ //
300
327
Stomp . prototype . disconnect = function ( ) {
301
328
_disconnect ( this ) ;
302
329
}
303
330
304
- /**
305
- * Subscribe to destination (queue or topic)
306
- * @param {Object } headers
307
- */
331
+ //
332
+ // ## Stomp.subscribe()
333
+ //
334
+ // **Subscribe to destination (queue or topic)**
335
+ //
336
+ // Takes a header object
337
+ //
338
+ // Takes a callback function
339
+ //
308
340
Stomp . prototype . subscribe = function ( headers , callback ) {
309
341
var destination = headers [ 'destination' ] ;
310
342
headers [ 'session' ] = this . session ;
@@ -313,10 +345,13 @@ Stomp.prototype.subscribe = function(headers, callback) {
313
345
this . log . debug ( 'subscribed to: ' + destination + ' with headers ' + sys . inspect ( headers ) ) ;
314
346
} ;
315
347
316
- /**
317
- * Unsubscribe from destination (queue or topic)
318
- * @param {Object } headers
319
- */
348
+ //
349
+ // ## Stomp.unsubscribe()
350
+ //
351
+ // **Unsubscribe from destination (queue or topic)**
352
+ //
353
+ // Takes a header object
354
+ //
320
355
Stomp . prototype . unsubscribe = function ( headers ) {
321
356
var destination = headers [ 'destination' ] ;
322
357
headers [ 'session' ] = this . session ;
@@ -325,50 +360,67 @@ Stomp.prototype.unsubscribe = function(headers) {
325
360
this . log . debug ( 'no longer subscribed to: ' + destination ) ;
326
361
} ;
327
362
328
- /**
329
- * Acknowledge received message
330
- * @param {String } message id to acknowledge
331
- */
363
+ //
364
+ // ## Stomp.ack()
365
+ //
366
+ // **Acknowledge received message**
367
+ //
368
+ // Takes a string representing the message id to ack
369
+ //
332
370
Stomp . prototype . ack = function ( message_id ) {
333
371
send_command ( this , 'ACK' , { 'message-id' : message_id } ) ;
334
372
this . log . debug ( 'acknowledged message: ' + message_id ) ;
335
373
} ;
336
374
337
- /**
338
- * Begin transaction
339
- * @return {String } generated transaction id
340
- */
375
+ //
376
+ // ## Stomp.begin()
377
+ //
378
+ // **Begin transaction**
379
+ //
380
+ // Return a string representing the generated transaction id
381
+ //
341
382
Stomp . prototype . begin = function ( ) {
342
383
var transaction_id = Math . floor ( Math . random ( ) * 99999999999 ) . toString ( ) ;
343
384
send_command ( this , 'BEGIN' , { 'transaction' : transaction_id } ) ;
344
385
this . log . debug ( 'begin transaction: ' + transaction_id ) ;
345
386
return transaction_id ;
346
387
} ;
347
388
348
- /**
349
- * Commit transaction
350
- * @param {String } transaction id generated by stomp.Stomp.begin()
351
- */
389
+ //
390
+ // ## Stomp.commit()
391
+ //
392
+ // **Commit transaction**
393
+ //
394
+ // Takes a string representing the transaction id generated by stomp.Stomp.begin()
395
+ //
352
396
Stomp . prototype . commit = function ( transaction_id ) {
353
397
send_command ( this , 'COMMIT' , { 'transaction' : transaction_id } ) ;
354
398
this . log . debug ( 'commit transaction: ' + transaction_id ) ;
355
399
} ;
356
400
357
- /**
358
- * Abort transaction
359
- * @param {String } transaction id generated by stomp.Stomp.begin()
360
- */
401
+ //
402
+ // ## Stomp.abort()
403
+ //
404
+ // **Abort transaction**
405
+ //
406
+ // Takes a string representing the transaction id generated by stomp.Stomp.begin()
407
+ //
361
408
Stomp . prototype . abort = function ( transaction_id ) {
362
409
send_command ( this , 'ABORT' , { 'transaction' : transaction_id } ) ;
363
410
this . log . debug ( 'abort transaction: ' + transaction_id ) ;
364
411
} ;
365
412
366
- /**
367
- * Send MESSAGE to STOMP broker
368
- * @param {Object } headers required (destination is required)
369
- * @param {Bool } do you want a receipt of the message sent?
370
- * @return {Object } Frame object of message sent
371
- */
413
+ //
414
+ // ## Stomp.send()
415
+ //
416
+ // **Send MESSAGE to STOMP broker**
417
+ //
418
+ // Takes a header object (destination is required)
419
+ //
420
+ // Takes a boolean requesting recipt of the sent message
421
+ //
422
+ // Returns a `Frame` object representing the message sent
423
+ //
372
424
Stomp . prototype . send = function ( headers , want_receipt ) {
373
425
var destination = headers [ 'destination' ] ,
374
426
body = headers [ 'body' ] || null ;
0 commit comments