I'm using rhea to connect a NestJS application to a AMQP 1.0 server using the following code.
const host = <some url>; // I from some external source
const port = <some port number>; // I get from external source
const target = <some queue name>; // I get from external source
const container = rhea.create_container();
container.on('message', function (context) {
console.log(context.message.body);
context.connection.close();
});
container.once('sendable', function (context) {
context.sender.send({body:'Hello World!'});
});
const keyFile = '<path to key file>';
const certFile = '<path to cert file>';
const caFile = '<path to CA file>';
const ca = fs.readFileSync(caFile);
const cert = fs.readFileSync(certFile);
const key = fs.readFileSync(keyFile);
const opts: rhea.ConnectionOptions = {
host: host,
port: port,
transport: 'tls',
key: key,
cert: cert,
ca: [ca],
hostname: host,
};
const connection = container.connect(opts);
connection.open_receiver(target);
connection.open_sender(target);
connection.send({ body: 'Hello world'});
Where I get the target, host, and port from calls to some REST API endpoint.
This results in the following error
console.error
{
error: ConnectionError {
message: "Permission PERFORM_ACTION(connect) is denied for : VirtualHost '<hostname>' on VirtualHostNode 'default'",
name: 'ConnectionError',
condition: 'amqp:not-allowed',
description: "Permission PERFORM_ACTION(connect) is denied for : VirtualHost '<hostname>' on VirtualHostNode 'default'"
},
...
...
Reading this error message, one would think that the certificates I'm using are not allowing me to connect to the server, but that seems strange, as previous attempts gave me "unable to log in"- messages. My question is then what about the VirtualHostNode?
I try to set it to something, in the sender_options.target.address = serverPath
, but this seems to not have the intended effect, since the error message says VirtualHostNode: default
, which is not what I set the property in the options object to, I also try to set it in the open_sender(serverPath)
call, but to no avail.
Excerpt from the documentation says
open_sender(address|options)
Establishes a link over which messages can be sent and returns a Sender representing that link. A sending link is an analogous concept to a subscription for outgoing rather than incoming messages. I.e. it expresses a desire to send messages.
The argument to this method can either be a simple string indicating the target for messages of interest (e.g. a queue name), or an options object that may contain any of the following fields:
target - The target to which messages are sent. This can be a simple string address/name or a nested object itself containing the fields:
address
dynamic
expiry_policy
durable
source - The source of a sending link is the local identifier. It is usually not needed, but can be set if it is,
name - The name of the link. This should be unique for the container. If not specified a unqiue name is generated.
autosettle - Whether sent messages should be automatically settled once the peer settles them. Defaults to true.
...
...
Where do I set the queue to connect to, if not in the open_sender
/open_receiver
methods, nor the connection object, how do I do that?