Skip to main content

AMQP

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

Tagsqueuerabbitmq
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.

Credential configuration

To configure this credential, you need to fill the credential configuration form with the RabbitMQ connection parameters: host, port, username, password and vhost.

If you check the Use promise API option, you'll be able to use the library using promises; otherwise, the credential will use the callback API. You can only use one of both ways.

In the extra options field, you can include any of the parameters you found here.

Here is an example of a filled credential configuration form in YepCode:

AMQP Snippets available in 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"));
});
};