English 中文(简体)
Papasar Node js app——消费者。 接收功能妨碍了整个功能
原标题:Apache Pulsar Node js app - consumer.receive function has blocked the whole functionality

我正在不断阅读信息。 如果没有任何信息可以读到,我想关闭我的客户和消费者。

下面的法典如果有读到的电文,但读到所封存的所有电文后,就会被罚款。 <代码>consumer.receive(>”方法阻止了整个方案。

我做了什么错误?

const RECEIVE_TIMEOUT = 100; // Adjust based on your needs

while (true) {
  const msg = await consumer.receive(RECEIVE_TIMEOUT);
  if (!msg) {
    // No message received within timeout, handle empty queue scenario
  } else {
    // Process the received message
    consumer.acknowledge(msg);
  }
}
问题回答

I think the reader API is more suitable for this case. Here is the documentation https://pulsar.apache.org/docs/next/client-libraries-node-use/#create-a-reader

if (reader.hasNext()) {
    const msg = reader.readNext();
} else {
    reader.close();
    client.close();
}




相关问题
How to make Sequelize use singular table names

I have an model called User but Sequelize looks for the table USERS whenever I am trying to save in the DB. Does anyone know how to set Sequelize to use singular table names? Thanks.

What is Node.js? [closed]

I don t fully get what Node.js is all about. Maybe it s because I am mainly a web based business application developer. What is it and what is the use of it? My understanding so far is that: The ...

Clientside going serverside with node.js

I`ve been looking for a serverside language for some time, and python got my attention somewhat. But as I already know and love javascript, I now want learn to code on the server with js and node.js. ...

Can I use jQuery with Node.js?

Is it possible to use jQuery selectors/DOM manipulation on the server-side using Node.js?

How do I escape a string for a shell command in node?

In nodejs, the only way to execute external commands is via sys.exec(cmd). I d like to call an external command and give it data via stdin. In nodejs there does yet not appear to be a way to open a ...

热门标签