Guest User

Untitled

a guest
Feb 14th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. 'use strict'
  2.  
  3. const config = require('config')
  4.  
  5. const rabbit = require('rabbot')
  6.  
  7. const settings = {
  8. connection: {
  9. user: "guest",
  10. pass: "guest",
  11. server: "rabbitmq",
  12. port: 5672,
  13. timeout: 2000,
  14. vhost: "%2f",
  15. heartbeat: 10,
  16. failAfter: 30,
  17. retryLimit: 3,
  18. replyQueue: false
  19. },
  20. exchanges: [
  21. {
  22. name: 'notification-attempt',
  23. type: 'topic',
  24. persistent: true,
  25. publishTimeout: 1e3,
  26. },
  27. {
  28. name: 'notification-attempt-delayed',
  29. type: 'direct',
  30. persistent: true,
  31. publishTimeout: 1e3,
  32. }
  33. ],
  34. queues: [
  35. {
  36. name: 'notification-attempt-checker',
  37. durable: true,
  38. },
  39. {
  40. name: 'notification-attempt-checker-delayed',
  41. deadLetter: 'notification-attempt',
  42. durable: true,
  43. },
  44. ],
  45. bindings: [
  46. {
  47. exchange: 'notification-attempt',
  48. target: 'notification-attempt-checker',
  49. keys: [
  50. 'notification.attempt'
  51. ]
  52. },
  53. {
  54. exchange: 'notification-attempt-delayed',
  55. target: 'notification-attempt-checker-delayed',
  56. keys: [
  57. 'notification.attempt'
  58. ]
  59. }
  60. ]
  61. }
  62.  
  63. rabbit.configure(settings).done(() => {
  64. console.info('CONFIGURED')
  65.  
  66. rabbit.handle('notification.attempt', (msg) => {
  67. console.info('RECEIVE1', new Date())
  68. console.info(JSON.stringify(msg.body))
  69. msg.ack()
  70. }, 'notification-attempt-checker')
  71. rabbit.startSubscription('notification-attempt-checker')
  72.  
  73. const publish = () => {
  74. console.info('SEND', new Date())
  75. rabbit.publish('notification-attempt-delayed', {
  76. type: 'notification.attempt',
  77. body: {
  78. message: 'hola'
  79. },
  80. expiresAfter: 3e3,
  81. persistent: true
  82. })
  83. }
  84. setTimeout(publish, 1e3)
  85. })
Add Comment
Please, Sign In to add comment