apache / pulsar-client-node

Apache Pulsar NodeJS Client
https://pulsar.apache.org/
Apache License 2.0
148 stars 86 forks source link

can't receive msgs with listener #342

Closed ilaipi closed 1 year ago

ilaipi commented 1 year ago

I create a consumer like this:

// test.js
const net = require('net');
const Pulsar = require('pulsar-client');

(async () => {
  // Create a client
  const client = new Pulsar.Client({
    serviceUrl: 'my-pulsar-url', // e.g. pulsar://xxx:6650
  });

  // Create a consumer
  const consumer = await client.subscribe({
    topic: 'mytopic',
    subscription: 'my-sub',
    subscriptionType: 'Exclusive',
    listener: (msg, msgConsumer) => {
      console.log(msg.getData().toString());
      msgConsumer.acknowledge(msg);
    },
  });
  net.createServer().listen();
})();

When I run node test.js, I will receive msgs if have sent some msgs.

then keep the process live, I can't receive any more new msgs. and if I close the process, and re-run node test.js, I will got all msgs sent just now.

what's wrong? thanks

ilaipi commented 1 year ago

use the latest version of sdk

Pulsar server is standard lone mode, version 3.1.0

ilaipi commented 1 year ago

maybe this is because the pulsar server.

I change to while (true) { consumer.receive() } and then got error: already close

so maybe my pulsar client always auto closed after connected.

use bull instead.

viktorvsk commented 10 months ago

I have similar issue. listener parameter stops working after a couple of messages and gets more after restart, while while (true) { await consumer.receive() } works completely as expected.

Maybe its just incomplete docs and requires a small fix, but at first sight it should work, I'm going to create new issue if once I confirm this is a case and prepare an actual reproduction