How to use amqp-connection-manager - 10 common examples

To help you get started, we’ve selected a few amqp-connection-manager examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github assemblee-virtuelle / Semantic-Bus / engine / app.js View on Github external
fs.writeFile('configuration.js', content, 'utf8', function(err) {
    if (err) {
      throw err
    } else {
      console.log(configJson);
      let connection = amqpManager.connect([(configJson.socketServerEngine ? configJson.socketServerEngine : configJson.socketServer) + '/' + configJson.amqpHost]);
      let communication= require('./communication');
      var channelWrapper = connection.createChannel({
        json: true,
        setup: function(channel) {
          channel.assertQueue('work-ask', {
            durable: true
          })
          onConnect(channel);
          // `channel` here is a regular amqplib `ConfirmChannel`.
          // Note that `this` here is the channelWrapper instance.
          // return channel.assertQueue('rxQueueName', {
          //   durable: true
          // });
        }
      });
      // amqp.connect((configJson.socketServerEngine ? configJson.socketServerEngine : configJson.socketServer) + '/' + configJson.amqpHost, (err, conn) => {
github assemblee-virtuelle / Semantic-Bus / main / app.js View on Github external
throw err
    } else {
      const securityService = require('./server/services/security')
      safe.use(function(req, res, next) {
        securityService.securityAPI(req, res, next)
      })
      app.set('etag', false)
      unSafeRouteur.use(cors())
      console.log('connection to ----', configJson.socketServer + '/' + configJson.amqpHost)
      // amqp.connect(configJson.socketServer + '/' + configJson.amqpHost, function (err, conn) {
      //   console.log('AMQP status : ', conn ? 'connected' : 'no connected', err || 'no error')
      //   conn.createChannel(function (_err, ch) {
      //     onConnect(ch)
      //   })
      // })
      let connection = amqpManager.connect([configJson.socketServer + '/' + configJson.amqpHost]);
      var channelWrapper = connection.createChannel({
        json: true,
        setup: function(channel) {
          channel.assertQueue('work-ask', {
            durable: true
          })
          onConnect(channel);
        }
      });
      const onConnect = function(amqpClient) {
        console.log("connected to amqp")
      }
      app.use('/configuration', unSafeRouteur)
      app.use('/data/api', unSafeRouteur)
      app.use('/data/specific', safe)
github amazeeio / lagoon / services / logs2slack / src / index.js View on Github external
// @flow

const amqp = require('amqp-connection-manager');
const { logger } = require('@lagoon/commons/src/local-logging');
const readFromRabbitMQ = require('./readFromRabbitMQ');

import type { ChannelWrapper } from './types';

const rabbitmqHost = process.env.RABBITMQ_HOST || "broker"
const rabbitmqUsername = process.env.RABBITMQ_USERNAME || "guest"
const rabbitmqPassword = process.env.RABBITMQ_PASSWORD || "guest"
const connection = amqp.connect([`amqp://${rabbitmqUsername}:${rabbitmqPassword}@${rabbitmqHost}`], { json: true });

connection.on('connect', ({ url }) => logger.verbose('Connected to %s', url, { action: 'connected', url }));
connection.on('disconnect', params => logger.error('Not connected, error: %s', params.err.code, { action: 'disconnected', reason: params }));

// Cast any to ChannelWrapper to get type-safetiness through our own code
const channelWrapperLogs: ChannelWrapper = connection.createChannel({
	setup: channel => {
		return Promise.all([
			channel.assertExchange('lagoon-logs', 'direct', {durable: true}),
			channel.assertQueue('lagoon-logs:slack', {durable: true}),
			channel.bindQueue('lagoon-logs:slack', 'lagoon-logs', ''),
			channel.prefetch(1),
			channel.consume('lagoon-logs:slack', msg => readFromRabbitMQ(msg, channelWrapperLogs), {noAck: false}),
		]);
	}
});
github wherefortravel / bull-amqp / src / index.js View on Github external
// @flow

import Queue from './Queue'

require('amqp-connection-manager/lib/ChannelWrapper').default.prototype._runOnce = function(fn) {
  return this.waitForConnect().then(() => fn(this._channel))
}

export default Queue
github AlariCode / nestjs-rmq / lib / rmq.service.ts View on Github external
public async init(): Promise {
		this.logger.watch(CONNECTING_MESSAGE);
		const connectionURLs: string[] = this.options.connections.map((connection: IRMQConnection) => {
			return `amqp://${connection.login}:${connection.password}@${connection.host}`;
		});
		const connectionOptins = {
			reconnectTimeInSeconds: this.options.reconnectTimeInSeconds
				? this.options.reconnectTimeInSeconds
				: DEFAULT_RECONNECT_TIME,
		};
		this.server = amqp.connect(connectionURLs, connectionOptins);
		this.channel = this.server.createChannel({
			json: false,
			setup: async (channel: Channel) => {
				await channel.assertExchange(this.options.exchangeName, EXCHANGE_TYPE, {
					durable: this.options.isExchangeDurable ? this.options.isExchangeDurable : true,
				});
				if (this.options.queueName) {
					this.listen(channel);
				}
				await channel.prefetch(
					this.options.prefetchCount ? this.options.prefetchCount : 0,
					this.options.isGlobalPrefetchCount ? this.options.isGlobalPrefetchCount : false
				);
				channel.consume(
					this.replyQueue,
					(msg: Message) => {
github wherefortravel / bull-amqp / src / Queue.js View on Github external
async _setup() {
    if (this._conn) {
      return
    }

    this._resetToInitialState()

    this._conn = connections.connect(this._options.connectionString)
    const conn = this._conn

    this._chan = conn.createChannel()

    conn.on('error', (err) => {
      this.emit('connection:error', err)
    })

    conn.on('close', (err) => {
      this.emit('connection:close', err)
    })
  }
github poanetwork / tokenbridge / oracle / src / services / amqpClient.js View on Github external
require('../../env')
const connection = require('amqp-connection-manager').connect(process.env.ORACLE_QUEUE_URL)
const logger = require('./logger')
const { getRetrySequence } = require('../utils/utils')

connection.on('connect', () => {
  logger.info('Connected to amqp Broker')
})

connection.on('disconnect', () => {
  logger.error('Disconnected from amqp Broker')
})

function connectWatcherToQueue({ queueName, workerQueue, cb }) {
  const queueList = workerQueue ? [queueName, workerQueue] : [queueName]

  const channelWrapper = connection.createChannel({
    json: true,
github AlariCode / nestjs-rmq / lib / server / server.ts View on Github external
private async start(callback?: () => void) {
        this.server = amqp.connect(this.urls);
        this.server.on(CONNECT_EVENT, () => {
            this.channel = this.server.createChannel({
                json: false,
                setup: async (channel) => {
                    await channel.assertQueue(this.queue, this.queueOptions);
                    await channel.prefetch(this.prefetchCount, this.isGlobalPrefetchCount);
                    channel.consume(this.queue, (msg) => this.handleMessage(msg), { noAck: true });
                    if (callback instanceof Function) {
                      callback();
                    }
                },
            });
        });

        this.server.on(DISCONNECT_EVENT, err => {
            this.logger.error(DISCONNECT_MESSAGE);
github ramesaliyev / mom / libraries / rabbitmq.ts View on Github external
protected connect({ host, port, user, pass }) {
    return this.conn = amqpConnManager.connect({
      url: `amqp://${user}:${pass}@${host}:${port}`,
      json: true,
      connectionOptions: {
        heartbeat: 30,
      }
    });
  }
github amazeeio / lagoon / node-packages / commons / src / logs.js View on Github external
function initSendToLagoonLogs() {
  const connection = amqp.connect(
    [`amqp://${rabbitmqUsername}:${rabbitmqPassword}@${rabbitmqHost}`],
    { json: true },
  );

  connection.on('connect', ({ url }) =>
    logger.verbose('lagoon-logs: Connected to %s', url, {
      action: 'connected',
      url,
    }),
  );
  connection.on('disconnect', params =>
    logger.error('lagoon-logs: Not connected, error: %s', params.err.code, {
      action: 'disconnected',
      reason: params,
    }),
  );

amqp-connection-manager

Auto-reconnect and round robin support for amqplib.

MIT
Latest version published 1 year ago

Package Health Score

62 / 100
Full package analysis