0

I can't find a solution or any hints online regarding my problem.

I want to set up central configuration manager with Apache Zookeeper for my Spring Boot application which can have multiple instances at the same time.

So in Zookeeper, I would only have some kind of data which are ranges:

0-100

101-200

...

900-1000...

Let's say that I have two instances (A and B) of application at the start. Then instance A would get range 0-100 and instance B would get next available range which is 101-200. If a new instance is added or some instance is restarted then it would get next available range. Each instance would only need to read data from configuration once and that is on an instance startup.

I know to read data from Zookeeper with @Value and @ConfigurationProperties.

To be specific with questions:

  • How to configure Zookeeper in this way so once data is read it is not valid or relevant anymore?
  • How to set up in Spring Boot to read configuration from Zookeeper only once, on application startup?

1 Answers1

0
  1. If a new instance is added or some instance is restarted then it would get next available range.

You can create a ZNode "/counter" and write there start value (1). Everytime when you start a new instance of your application, you should ask this ZNode for a current value and set the new one (in your case if it was 1, new one should be 1+100=101). Also you need to check version of the record when you updating the value in ZNode.

  1. How to configure Zookeeper in this way so once data is read it is not valid or relevant anymore?

You could write some 'invalid' value in a ZNode or delete it.

  1. How to set up in Spring Boot to read configuration from Zookeeper only once, on application startup?

You can do whatever you want on application startup in the method 'main(String[] args)' (where you starting the Spring app). So, you can read configuration right here, it will be performed just once. Sorry, i didn't work with the Spring Cloud (:

Snatch
  • 1