Skip to content

nacho270/apache-pulsar-demo

Repository files navigation

Apache pulsar demo

Code example

For a simple glimpse of use cases, have a look at apache-pulsar-demo-consumer/src/test/java/com/nacho/pulsar/demo/consumer/TestCases.java

How to use?

There are 2 options:

  • Run infra only: docker-compose -f docker-compose-infra.yml up

    • In this case you'll need to run the producer and consumer manually from the ide/maven.
  • Run infra + 1 producer + 2 consumers: docker-compose up

In both cases, you'll get have the following local urls:

Dealing with lag

In pulsar, the lag is known as msgBacklog. And instead of reset the offset, the term is skip messages.

You'll need to know the msgBacklog of the topic and then skip those for a subscription.

  • Get stats: bin/pulsar-admin topics stats persistent://sample/pulsar/ns1/key_shared-topic

  • Skip: bin/pulsar-admin topics skip persistent://sample/pulsar/ns1/key_shared-topic -n 430 -s key_shared-subscription

Simulating lag

  • Start producing continuously while true; do echo "Sending..."; curl -XPOST localhost:7070/produce/key-shared; sleep 1; done

  • Stop consumers: Either stop manually from the IDE or do docker stop apache-pulsar-demo_consumer-1_1 && docker stop apache-pulsar-demo_consumer-2_1

  • You'll see lag accumulating in grafana localBacklog and in Prometheus.

  • To restart the consumers either run it manually from the IDE or do docker start apache-pulsar-demo_consumer-1_1 && docker start apache-pulsar-demo_consumer-2_1

Useful links

Setup:

Monitoring:

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published