Skip to content

Instantly share code, notes, and snippets.

View bondvt04's full-sized avatar

Anatoliy Bondar bondvt04

View GitHub Profile
@bondvt04
bondvt04 / amqp-send-to-retry.js
Last active March 12, 2018 10:52
RabbitMQ retries - send failed messages to retry loop
// emulate some job which can be failed
function handler() {
return Math.random() > 0.1 ? Promise.resolve() : Promise.reject()
}
channel.consume('comments', msg => {
return (new Promise((resolve, reject) => {
if (msg.fields.redelivered) {
reject('Message was redelivered, so something wrong happened');
return;
@bondvt04
bondvt04 / amqp-create-set.js
Created March 12, 2018 10:18
RabbitMQ retries - creating retry set: 1 TTLX, 3 ttl queues and 1 DLX
assertExchanges()
.then(assertQueues)
.then(bindExchangesToQueues);
function assertExchanges() {
return Promise.all([]
.concat(
channel.assertExchange('A_COMMENT_CREATED', 'fanout', { durable: true }),
channel.assertExchange('A_COMMENT_DELETED', 'fanout', { durable: true }),
channel.assertExchange('A_COMMENT_UPDATED', 'fanout', { durable: true })
@bondvt04
bondvt04 / amqp.js
Last active September 20, 2022 02:01
RabbitMQ retries
'use strict';
const AmqpClient = require('amqplib');
const Promise = require('bluebird');
const contentTypeJson = 'application/json';
const contentEncoding = 'utf8';
const config = {
exchanges: [
{ name: 'A_COMMENT_CREATED', type: 'fanout' },
{ name: 'A_COMMENT_DELETED', type: 'fanout' },