Reader small image

You're reading from  Mastering Spring Cloud

Product typeBook
Published inApr 2018
Reading LevelIntermediate
PublisherPackt
ISBN-139781788475433
Edition1st Edition
Languages
Right arrow
Author (1)
Piotr Mińkowski
Piotr Mińkowski
author image
Piotr Mińkowski

Piotr works as a Solution Architect at Red Hat. He has several years of experience in software architecture and development. During this time, he was working in large organizations, where he was responsible for IT transformation to the modern cloud-native development approach. He is interested in technologies related to programming, containerization, and microservices. He writes about it in his blog https://piotrminkowski.com.
Read more about Piotr Mińkowski

Right arrow

Chapter 10. Additional Configuration and Discovery Features

We talked a great deal about service discovery and distributed configuration in Chapter 4, Service Discovery, and Chapter 5, Distributed Configuration with Spring Cloud Config. We discussed two solutions in detail. The first of them, Eureka, is provided by Netflix OSS and has been adopted by Spring Cloud for service discovery. The second was the Spring Cloud Config project dedicated only to a distributed configuration. However, there are some interesting solutions on the market effectively combining both of these features. Currently, Spring Cloud supports two of them:

  • Consul: This product is built by HashiCorp. It is a highly available, distributed solution designed to connect and configure applications across dynamic, distributed infrastructure. Consul is a rather complex product, and has multiple components, but its main functionality is discovering and configuring services across any infrastructure.
  • Zookeeper: This product is built...

Using Spring Cloud Consul


The Spring Cloud Consul project provides integration for Consul and Spring Boot applications through auto-configuration. By using the well-known Spring Framework annotation style, we may enable and configure common patterns within microservice-based environments. These patterns include service discovery using Consul agent, distributed configuration using Consul key/value store, distributed events with Spring Cloud Bus, and Consul Events. The project also supports a client-side load balancer based on Netflix's Ribbon and an API gateway based on Netflix's Zuul. Before we start to discuss these features, we first have to run and configure Consul agent.

Running Consul agent

We will begin with the simplest way of starting Consul agent on our local machines. The standalone development mode may be easily set up with the Docker container. Here's the command, which will start the Consul container from the official Hashicorp's image available on Docker Hub:

docker run -d --name...

Using Spring Cloud Zookeeper


Spring Cloud supports various products used as a part of the microservices architecture. You can find this out when reading this chapter where Consul has been compared with Eureka as a discovery tool, and with Spring Cloud Config as a distributed configuration tool. Zookeeper is another solution that might serve as an alternative choice to those listed previously. As with Consul, it can be used for both service discovery and distributed configuration. To enable Spring Cloud Zookeeper in the project, you should include the spring-cloud-starter-zookeeper-discovery starter for the service discovery feature, or spring-cloud-starter-zookeeper-config for the configuration server feature. Alternatively, you may declare a spring-cloud-starter-zookeeper-all dependency that activates all functionalities for the application. Don't forget to include spring-boot-starter-web, which is still required to provide web functionality:

<dependency>
    <groupId>org.springframework...

Summary


In this chapter, I have guided you through the main features of two Spring Cloud projects—Consul and Zookeeper. I haven't focused only on Spring Cloud functionalities, but have also given you the instructions on how to start, configure, and maintain instances of its tools. We have discussed even more advanced scenarios, such as setting up a cluster consisting of numerous members using Docker. There, you had a chance to see the true power of Docker as a development tool. It allowed us to initialize a cluster that consists of three members just by using three simple commands, without any additional configuration.

Consul seems to be an important alternative to Eureka as a discovery server when using Spring Cloud. I cannot say the same about Zookeeper. As you have probably noticed, I have written much more about Consul than Zookeeper. Also, Spring Cloud treats Zookeeper as a second choice. It still does not have a zoning mechanism or watching capability for configuration changes that...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Mastering Spring Cloud
Published in: Apr 2018Publisher: PacktISBN-13: 9781788475433
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Piotr Mińkowski

Piotr works as a Solution Architect at Red Hat. He has several years of experience in software architecture and development. During this time, he was working in large organizations, where he was responsible for IT transformation to the modern cloud-native development approach. He is interested in technologies related to programming, containerization, and microservices. He writes about it in his blog https://piotrminkowski.com.
Read more about Piotr Mińkowski