ack.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. module("Stomp Acknowledgement");
  2. test("Subscribe using client ack mode, send a message and ack it", function() {
  3. var body = Math.random();
  4. var client = Stomp.client(TEST.url);
  5. client.debug = TEST.debug;
  6. client.connect(TEST.login, TEST.password, function() {
  7. var onmessage = function(message) {
  8. start();
  9. // we should receive the 2nd message outside the transaction
  10. equals(message.body, body);
  11. var receipt = Math.random();
  12. client.onreceipt = function(frame) {
  13. equals(receipt, frame.headers['receipt-id'])
  14. client.disconnect();
  15. }
  16. message.ack({'receipt': receipt});
  17. }
  18. var sub = client.subscribe(TEST.destination, onmessage, {'ack': 'client'});
  19. client.send(TEST.destination, {}, body);
  20. });
  21. stop(TEST.timeout);
  22. });
  23. test("Subscribe using client ack mode, send a message and nack it", function() {
  24. var body = Math.random();
  25. var client = Stomp.client(TEST.url);
  26. client.debug = TEST.debug;
  27. client.connect(TEST.login, TEST.password, function() {
  28. var onmessage = function(message) {
  29. start();
  30. equals(message.body, body);
  31. var receipt = Math.random();
  32. client.onreceipt = function(frame) {
  33. equals(receipt, frame.headers['receipt-id'])
  34. client.disconnect();
  35. }
  36. message.nack({'receipt': receipt});
  37. }
  38. var sub = client.subscribe(TEST.destination, onmessage, {'ack': 'client'});
  39. client.send(TEST.destination, {}, body);
  40. });
  41. stop(TEST.timeout);
  42. });