2

I am developing a microservice, using Spring Boot, that exposes REST Endpoint.

To meet the scalability constrains, multiple instance of the [same] service will be deployed (basically scale up when needed and scale down when not needed).

I am using the Spring Cloud Config Server to supply the configuration (such as port to bound, and other configurations) to this service.

Since the service exposing REST api, How can configure the config server to supply a unique port to each instance of the microservice?

One possible solution could be, running the service in individual machine/VM or create a docker container and deploy the service. This could be my solution if there is no way to supply random port to the service from cloud config server.

2
  • you can also use a random port if you want. server.port=0 Commented Feb 2, 2017 at 12:48
  • Scalability and resiliance comes from multiple instances on different machines in which case the port can be the same. Are you using Netflix? If so then your services register with Eureka and are software load-balanced through Zuul. Multiple Zuul instances are registered to your website reverse proxy, e.g. Apache balancer workers or a hardware device. Commented Feb 2, 2017 at 14:48

2 Answers 2

2

You could start each of the three instances with a different Spring profile. E.g. SPRING_PROFILES_ACTIVE=prod1 for the first instance, SPRING_PROFILES_ACTIVE=prod2 for the second, etc.

Then you could set the port in application-prod1.properties, application-prod2.properties, etc (or in yaml files).

You could also run the app in cloudfoundry. Then cloudfoundry will create the different containers for you.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the suggestion. The suggestion is close enough; but will not solve the issue completely. When there will be more request to the service, i could not scale up beyond certain level.
Indeed. You would have to generate many application.properties files in advance. And then set the environment variables via a shell script. But in this case I would prefer the solution Patrick mentioned above in his comment using server.port=0.
0

Have you tried using spring-cloud-bus with rabbit MQ it is basically to broadcast your configuration changes to all the instances of your application through POST bus/refresh.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.