Skip to main content

AMQP

The Advanced Message Queuing Protocol (AMQP) is an open standard application layer protocol for message-oriented middleware

Network Connection needs

This integration needs network access to the server where the service is running.

See the Network access page for details about how to achieve that.

AMQP snippets available in YepCode editor#

note

The title is the triggering text for YepCode to autocomplete the script

Integration#

New integration from credential
const amqpConnection = await yepcode.integration.amqp('credential-slug')
New integration from plain authentication data
const amqp = require('amqplib');
amqp.connect({  hostname: 'localhost',  username: 'guest',  password: 'guest',  port: '5672',  vhost: '/'}).then(connection => {  // Your code here}).catch(console.error);
New integration from plain authentication data with callback API
const amqp = require('amqplib/callback_api');
amqp.connect({  hostname: 'localhost',  username: 'guest',  password: 'guest',  port: '5672',  vhost: '/'},(error, connection) => {  if (error) {    console.error(error);  }  // Your code here});

Publisher (Promise)#

Publisher (promise)
const queue = 'queueName';
const publisher = (connection) => {  return connection.createChannel()  .then((channel) => {    return channel.assertQueue(queue).then((ok) => {      return channel.sendToQueue(queue, Buffer.from('Your message here'));    });  })  .catch((error) => console.error(error));};

Publisher (async/await)#

Publisher (async/await)
const queue = 'queueName';
const publisher = async (connection) => {  try {    const channel = await connection.createChannel();    await channel.assertQueue(queue);    channel.sendToQueue(queue, Buffer.from('Your message here'));  } catch (error) {    console.error(error);  }};

Publisher (Callback)#

Publisher (callback)
const queue = 'queueName';
const publisher = (connection) => {  connection.createChannel((error, channel) => {    if (error != null) console.error(error);    channel.assertQueue(queue);    channel.sendToQueue(queue, Buffer.from('Your message here'));  });};