RabbitMQ StompJs 只收到一条消息

RabbitMQ StompJs recieving just one Message

我正在尝试使用 Stomp 插件从 RabbitMq-Que 接收消息。这工作正常,但问题是我从队列中获取了每条消息。因此,如果队列有 13 条消息,我会得到 13 条消息。关键是我只想得到 1 条消息,然后在发送 Ack 或 Nack 后发送下一条消息。有人知道如何只收到一条消息吗?感谢您的帮助。

这是我得到的代码:

    GetMessage()
  {
    this.GetRabbitMqClient().then((client)=> 
    {

    var headers ={ack:'client', 'x-max-priority': '10'};
    var subscription = client.subscribe("/queue/TestQue",this.messageCallback,headers);    
  });
  }

private messageCallback = function(Message :IMessage)
  {
    console.log(Message.body);
    setTimeout(()=> {Message.ack();},100000000000000);        
  }

 private GetRabbitMqClient( ):Promise<Client> {
    var promise = new Promise<Client>((resolve,reject)=>{
    var client = new Client(
      {
        brokerURL: "ws://localhost:15674/ws",
        connectHeaders:
        {
          login: "guest",
          passcode: "guest"
        },
        // debug: function (str) {
        //   console.log(str);
        // },
        reconnectDelay: 5000,
        heartbeatIncoming: 4000,
        heartbeatOutgoing: 4000
      });

    client.onConnect = function (frame) {   
      resolve(client);
    };

    client.onStompError = function (frame) {
      // Will be invoked in case of error encountered at Broker
      // Bad login/passcode typically will cause an error
      // Complaint brokers will set `message` header with a brief message. Body may contain details.
      // Compliant brokers will terminate the connection after any error
      reject(frame);
      console.log('Broker reported error: ' + frame.headers['message']);
      console.log('Additional details: ' + frame.body);
    };
    client.activate();    
  });
  return promise;
  }

我找到了解决方案: 您只需要在 headers 属性中设置: 'prefetch-count':'1'