Guest User

Untitled

a guest
May 5th, 2013
71
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // index.js
  2. var amqp = require('amqp');
  3.  
  4. var connection = null;
  5.  
  6. connection = amqp.createConnection({ host: 'foo.com' });
  7.  
  8. connection.on('ready', function () {
  9.   connection.queue('loc', { durable: true, autoDelete: false}, function(q) {
  10.     q.bind('main', 'loc');
  11.     q.subscribe({ack:true, prefetchCount: 0}, function (message, headers, deliveryInfo) {
  12.       console.log(message);
  13.       setTimeout(function() { q.shift(); }, 100);
  14.     });
  15.   });
  16. });
  17.  
  18. my worker crashes only I run it AFTER there are messages in the queue. if I run the worker BEFORE, everything is ok.
  19.  
  20. I use ab to add 2 messages to the queue:
  21. ab -k -n 2 -c 1 -p post-data -T 'application/json' foo-api.com/publish
  22.  
  23. And now run my worker - node index.js
  24. here is the outputs:
  25.  
  26. { topic: 'loc',
  27.   sourceCode: 'LOC',
  28.   sourceRecordID: '690599224',
  29.   sourceField: 'Phone',
  30.   sourceFieldValue: '7572007395',
  31.   actionCode: 'DISP',
  32.   actionDescription: 'Disconnected Phone Number'
  33. }
  34. { topic: 'loc',
  35.   sourceCode: 'LOC',
  36.   sourceRecordID: '690599224',
  37.   sourceField: 'Phone',
  38.   sourceFieldValue: '7572007395',
  39.   actionCode: 'DISP',
  40.   actionDescription: 'Disconnected Phone Number'
  41. }
  42.  
  43. events.js:72
  44.         throw er; // Unhandled 'error' event
  45.               ^
  46. Error: PRECONDITION_FAILED - unknown delivery tag 2
  47.     at Queue._onMethod (/Users/ogolan/projects/quai-loc/worker/node_modules/amqp/amqp.js:1979:15)
  48.     at Queue.Channel._onChannelMethod (/Users/ogolan/projects/quai-loc/worker/node_modules/amqp/amqp.js:1557:14)
  49.     at Connection._onMethod (/Users/ogolan/projects/quai-loc/worker/node_modules/amqp/amqp.js:1088:28)
  50.     at AMQPParser.parser.onMethod (/Users/ogolan/projects/quai-loc/worker/node_modules/amqp/amqp.js:897:12)
  51.     at AMQPParser._parseMethodFrame (/Users/ogolan/projects/quai-loc/worker/node_modules/amqp/amqp.js:451:10)
  52.     at frameEnd (/Users/ogolan/projects/quai-loc/worker/node_modules/amqp/amqp.js:192:16)
  53.     at frame (/Users/ogolan/projects/quai-loc/worker/node_modules/amqp/amqp.js:177:14)
  54.     at AMQPParser.header [as parse] (/Users/ogolan/projects/quai-loc/worker/node_modules/amqp/amqp.js:163:14)
  55.     at AMQPParser.execute (/Users/ogolan/projects/quai-loc/worker/node_modules/amqp/amqp.js:236:21)
  56.     at Connection.<anonymous> (/Users/ogolan/projects/quai-loc/worker/node_modules/amqp/amqp.js:935:14)
RAW Paste Data