Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict'
- const config = require('config')
- const rabbit = require('rabbot')
- const settings = {
- connection: {
- user: "guest",
- pass: "guest",
- server: "rabbitmq",
- port: 5672,
- timeout: 2000,
- vhost: "%2f",
- heartbeat: 10,
- failAfter: 30,
- retryLimit: 3,
- replyQueue: false
- },
- exchanges: [
- {
- name: 'notification-attempt',
- type: 'topic',
- persistent: true,
- publishTimeout: 1e3,
- },
- {
- name: 'notification-attempt-delayed',
- type: 'direct',
- persistent: true,
- publishTimeout: 1e3,
- }
- ],
- queues: [
- {
- name: 'notification-attempt-checker',
- durable: true,
- },
- {
- name: 'notification-attempt-checker-delayed',
- deadLetter: 'notification-attempt',
- durable: true,
- },
- ],
- bindings: [
- {
- exchange: 'notification-attempt',
- target: 'notification-attempt-checker',
- keys: [
- 'notification.attempt'
- ]
- },
- {
- exchange: 'notification-attempt-delayed',
- target: 'notification-attempt-checker-delayed',
- keys: [
- 'notification.attempt'
- ]
- }
- ]
- }
- rabbit.configure(settings).done(() => {
- console.info('CONFIGURED')
- rabbit.handle('notification.attempt', (msg) => {
- console.info('RECEIVE1', new Date())
- console.info(JSON.stringify(msg.body))
- msg.ack()
- }, 'notification-attempt-checker')
- rabbit.startSubscription('notification-attempt-checker')
- const publish = () => {
- console.info('SEND', new Date())
- rabbit.publish('notification-attempt-delayed', {
- type: 'notification.attempt',
- body: {
- message: 'hola'
- },
- expiresAfter: 3e3,
- persistent: true
- })
- }
- setTimeout(publish, 1e3)
- })
Add Comment
Please, Sign In to add comment