Pulsar command-line tool to consume and then exit at end of data

  Kiến thức lập trình

For Kafka, I can run this on the command line, with a timeout:

kafka-console-consumer.sh --bootstrap-server <server> --topic <topic> --from-beginning --timeout-ms 1000

and it will consume all the messages in the topic and then exit.

Or, I can specify a limit on the number of messages, like this:

kafka-console-consumer.sh --bootstrap-server <server> --topic <topic> --from-beginning --max-messages <num> --timeout-ms 1000

and it will exit after consuming that number of messages, or, if there are less than that number messages, it will still exit after consuming all the messages.

I want to do something similar in Pulsar. I tried doing this:

pulsar-client --url <server> consume -s <some_name> -p Earliest -m NonDurable <topic_partition>

and it just consumed 1 message, because -n defaults to 1.

If I pass -n 0:

pulsar-client --url <server> consume -n 0 -s <some_name> -p Earliest -m NonDurable <topic_partition>

it will consume all messages, and then block and not exit.

If I pass a certain number of messages, like this:

pulsar-client --url <server> consume -n <num> -s <some_name> -p Earliest -m NonDurable <topic_partition>

it will consume that number of messages and exit, but if there aren’t that many messages, it will consume all messages, and then block and not exit.

What I want is a command-line tool that will exit after consuming all messages, in the case where I do not set a limit on number of messages, or where the limit is too high. Unfortunately, I don’t see any timeout parameter for the pulsar-client tool, like what I used for kafka-console-consumer.sh.

LEAVE A COMMENT