Skip to content

Latest commit

 

History

History
72 lines (40 loc) · 4.68 KB

README.md

File metadata and controls

72 lines (40 loc) · 4.68 KB

pulsar-failover-demo

A sample app that demos Pulsar client-side Controlled failover

This app has three components

  • A Provider app that works as a simple URL Service Provider as shown here. You must start one (only one) instance of this app before you start anything else (i.e. Producer or Consumer). If you plan on having more than one instance of this app for High-Availability (HA), you must put these instances behind a single HA load-balancer and the Producer and Consumer will need to access it via the load-balancer.
  • A Producer app that produce messages at regular intervals. You can start one of more instances of this app.
  • A Consumer app that consumes messages produced by the above Producer. You can start one of more instances of this app.

Below is a high-level diagram of the above components and the Pulsar Controlled Failover flow


Prerequisites

  • Java 11
  • Apache Maven 3.8.x (to build the app)
  • Pulsar 3.x
  • Two (or more) Pulsar based Streaming clusters
    • One clusters will be the Primary, while all the other clusters will be DR clusters that can takeover in case of a failover
    • For the purpose of this demo, we will use Astra Streaming (SaaS Streaming provider by DataStax) to standup two Pulsar based streaming clusters.

Building the app

From root of this repo, run command mvn clean package -Passembly

Running the app

First start the Provider app using command java -cp target/producer_failover-*-jar-with-dependencies.jar com.datastax.demo.streaming.provider.ClusterConfigProvider

Then start the Producer app using command java -cp target/producer_failover-*-jar-with-dependencies.jar com.datastax.demo.streaming.producer.ProducerApp

Finally start the Consumer app using command java -cp target/producer_failover-*-jar-with-dependencies.jar com.datastax.demo.streaming.consumer.ConsumerApp

Performing failover

The above demo app uses two Astra Streaming SaaS clusters (ideally deployed in different regions) with bidirectional replication. Internally it refers to them as clusterA and clusterB. Initially, clusterA is the default Primary and clusterB is DR/Failover.

You can find which cluster is currently Primary at anytime by hitting the Provider endpoint at /getConfig. If you are running the app locally, it can be accessed here http://localhost:8080/getconfig

To inject a failover, go to Provider endpoint /setConfig and pass the url param cluster-name with a value of the clusterA OR clusterB based on the cluster you want to failover to.

  • If running locally, you could initiate a failover hitting endpoint http://localhost:8080/setconfig?cluster-name=clusterB

Demo

  • Start Provider, followed by Producer and Consumer. Producer and Consumer messages show clusterA (useast1) as the primary (see below screenshots)

  • On Provider, check the current Cluster via a tool like Postname (see below screenshots)

  • On Provider, now perform failover to clusterB

  • Now Producer and Consumer messages should show clusterB (useast4) post failover