Zuul and Ribbon integration
Asked Answered
M

1

28

I have trouble understanding the connection between Zuul and Ribbon.

I think I got Zuul clear. It's a reverse proxy I can contact to reach one of my several instances of a service. It will pick the right server using a round-robin algorithm or whatever you configure it to do. It's a traditional load-balancer. To know the instances available it can use a registry like Eureka.

But I've got more trouble with Ribbon. It's sold as a client-side load balancer but what does it mean ? It doesn't need an external server ? Ribbon is embedded in the client the same way an Eureka client is ? If so how does it work ? Do I need Zuul when I use Ribbon, and vice-versa ?

On some articles, I saw that in fact, Zuul uses Ribbon by default for the load balancing part and it got me even more confused. If this is true what does "client-side" mean ? What does Zuul do except routing ?

I hope you can help me.

Mandrill answered 21/4, 2017 at 8:47 Comment(0)
C
43

Client and Server is always relative. Zuul is a client for your service instances and your service instances are servers for Zuul.

When we are using traditional load balancer (server-side load balancer), API caller (client) only knows a single endpoint that is a load balancer and the client doesn't know the list of servers. Load balancer chooses a server from the list.

When we are using client-side load balancer like Ribbon, API caller (client) should know the list of servers and choose one of them from the list. That's why we call it client-side load balancer.

As you know, Ribbon is a client-side load balancer module and is integrated to many http client modules. As an example, Feign and Load-balanced RestTemplate support Ribbon. Namely Feign and Load-balanced RestTemplate can choose a server from the given list or the list from eureka when used with ribbon.

Regarding Zuul, there is a RibbonRoutingFilter that routes your request to an actual service instance. RibbonRoutingFilter is using Ribbon to choose a server from the list that is given from your configuration or from Eureka. So if you want to use Zuul as a load-balanced reverse proxy, Zuul needs Ribbon.

Condemnation answered 2/5, 2017 at 0:17 Comment(3)
So am i correct in saying that all you need to do in order for zuul to load balance between eureka-registered running instances of a service is to have zuul-server application.properties file contain the eureka.client.serviceUrl.defaultZone property ?Rogelioroger
i.e. you use ribbon without having ever the need to even mention it because ribbon is bundled inside of zuul ?Rogelioroger
@xpz: Yes you are correct. Ribbon is a transitive dependency when you have Zuul in your pom.xml or gradle.build file. When you run the below command you will see Ribbon being added Maven: mvn dependency:tree Gradle: gradle dependenciesGranddaddy

© 2022 - 2024 — McMap. All rights reserved.