amqplib does not provide any specific method to create dynamically shovels, but you can do that using the Management HTTP-based API as specified in the docs: https://www.rabbitmq.com/shovel-dynamic.html#tutorial
So, in pure Node.js, this is and example of HTTP request (PUT method) to create a shovel programmatically:
var http = require('http');
var rabbit_host = "myrabbitmq.com";
var token = Buffer.from("admin:admin_pwd").toString('base64');
var shovel_name = "my_shovel";
var payload = {
"component": "shovel",
"vhost": "/",
"name": "my_shovel",
"value": {
"src-uri": "amqp://user1:pwd1@myrabbitmq.com",
"src-exchange": "test",
"dest-uri": "amqp://user2:pwd2@anotherbroker.com",
"dest-exchange-key": "test2",
"add-forward-headers": false,
"ack-mode": "on-confirm",
"delete-after": "never"
}
};
var options = {
"host": rabbit_host,
"port": 15672,
"path": "/api/parameters/shovel/%2F/" + shovel_name,
"method": "PUT",
"headers": {
"Authorization" : "Basic " + token,
"Content-Type" : "application/json",
}
}
var callback = function(response) {
var str = ''
response.on('data', function(chunk){
str += chunk;
});
response.on('end', function(){
console.log("end: response="+str);
});
}
var body = JSON.stringify(payload);
http.request(options, callback).end(body).on('error', function(e) {
console.log("error: " + e.message);
});
Obviously host "myrabbitmq.com" must be accessible from Node.js script on port 15672.
The example above creates a shovel from "myrabbitmq.com" to "anotherbroker.com", specifying exchanges for routing messages.