apache/pulsar-client-node

can't receive msgs with listener

ilaipi opened this issue · 3 comments

ilaipi commented

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

use the latest version of sdk

Pulsar server is standard lone mode, version 3.1.0

ilaipi commented

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.

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