【问题标题】:How could I increase consume timeout in rpc endpoint at rabbitmq?如何在 rabbitmq 的 rpc 端点中增加消耗超时?
【发布时间】:2021-03-01 13:41:51
【问题描述】:

我使用 RPC 端点,在其中一个端点中我有以下问题:我没有收到消息,所以回调函数没有在 channel.consume() 上执行。

在那个端点,我发送一条消息,一个需要时间的进程正在服务器端运行,它用一条关于进程是否正确执行的消息来响应我。在服务器立即发送消息的其他端点没有问题。

我认为超时有问题。我试图将对象 {timeout: 3600000} 放在 amqpOptions 之后,但问题还是没有解决。具体来说,无论我添加什么对象,连接和通道对象都具有相同的参数。如何正确更改超时?

const amqp = require('amqplib/callback_api');
const amqpOptions = {
  protocol: 'amqp',
  hostname: process.env.RABBITMQ_HOST,
  port: process.env.RABBITMQ_PORT,
  username: process.env.RABBITMQ_USER,
  password: process.env.RABBITMQ_PASS,
  vhost: '/',
};
const message = Buffer.from(JSON.stringify({}));
      amqp.connect(amqpOptions, (error0, connection) => {
        if (error0) { throw error0; }
        connection.createChannel((error1, channel) => {
          if (error1) { throw error1; }
          const correlationId = generateUuid();
          channel.consume(replyQueue, (msg) => {
            if (JSON.parse(msg.content).error) {
              console.log(JSON.parse(msg.content));
              const error = JSON.parse(msg.content.toString());
              return next(error);
            } 
            console.log(JSON.parse(msg.content));
            console.log('msg:',msg);
            const {tunnel_info} = JSON.parse(msg.content.toString());
          }, {noAck: true});
          channel.sendToQueue(`${brokerUri}`,
            message, {correlationId, contentType: 'application/json', contentEncoding: 'utf8', replyTo: replyQueue});
        });
      });

【问题讨论】:

    标签: javascript node.js rabbitmq message-queue node-amqp


    【解决方案1】:

    因为通道是单向的。您应该为发布和消费使用两个不同的渠道。

    AMQP 规范说:

    通道是unidirectional,因此在每个连接端点,传入和传出通道是完全不同的。

    【讨论】:

    • 其他URI也写了相同的代码,但是因为消息是从服务器立即发送的,所以我没有问题。
    猜你喜欢
    • 1970-01-01
    • 2019-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-12
    • 2020-07-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多