amqp rhea 连接到虚拟主机节点

问题描述 投票:0回答:0

我正在使用 rhea 使用以下代码将 NestJS 应用程序连接到 AMQP 1.0 服务器。

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'});

我从对某个 REST API 端点的调用中获取目标、主机和端口的位置。

这导致以下错误

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'"
      },
...
...

阅读此错误消息,有人会认为我正在使用的证书不允许我连接到服务器,但这似乎很奇怪,因为之前的尝试给了我“无法登录”消息。那么我的问题是 VirtualHostNode 呢?

我尝试在

sender_options.target.address = serverPath
中将它设置为某些东西,但这似乎没有达到预期的效果,因为错误消息说
VirtualHostNode: default
,这不是我在选项对象中设置的属性,我也尝试在
open_sender(serverPath)
调用中设置它,但无济于事。

文档摘录说

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

我在哪里设置要连接的队列,如果不是在

open_sender
/
open_receiver
方法中,也不在连接对象中,我该怎么做?

javascript node.js amqp rhea
© www.soinside.com 2019 - 2024. All rights reserved.