Example for Spring Cloud Consul with Ribbon for client side load balancing - spring

I see that spring-cloud-consul is live in spring.io [https://spring.io/blog/2015/05/27/spring-cloud-consul-1-0-0-m1-available-now] but I hardly see any reference examples.
I am mainly looking for Service Registration and Service Discovery with Consul and Ribbon as client side load balancer. Could someone give a sample application or an example to refer. I also checked in the git repository for spring-cloud-consul, didn't find any examples there[https://github.com/spring-cloud/spring-cloud-consul]

There is an example in the main repo, spring-cloud-consul-sample, that uses the LoadBalancerClient of which there is a ribbon implementation that will use consul to populate the server list.

I wasn't able to find much information about Consul and Ribbon, but I have found more information about Eueka (it's used by Netflix and it also does service registration/distcovery similiar to Consul). This Spring project seems to be a lot more active. Info about it can be found here: http://cloud.spring.io/spring-cloud-netflix/
This blog post demonstrates how to use spring cloud with Eueka and Ribbon: https://spring.io/blog/2015/07/14/microservices-with-spring
There is also a repo for the tutorial: https://github.com/paulc4/microservices-demo
If you still want to use Consul instead of Eueka, here is a sample project, you should be able to use this along with the blog post above to build a working example: https://github.com/spring-cloud/spring-cloud-consul/tree/master/spring-cloud-consul-sample

I wrote a demo project using Spring Cloud Consul and Spring Cloud Netflix.
I'm using Consul as a service registry, and Ribbon/Hystrix/Feign are used to simplify API service clients.
The project is hosted on GitHub: https://github.com/alexandreroman/number2words.

Related

confusion about Spring Data Flow Server

I'm confused about Spring Cloud Data Flow Server deployment...
We are planning to run it on cloudfoundry, and the instructions say one should download the final server artifact (a jar) and deploy it.
On the other hand another section in the documentation describes a way on how to customize the provisioning of roles to users with some custom code. But there is no explanation on how to embed the server in a custom application so I can provide my code (via #Bean).
On a very old blog post I found a mention of #EnableDataFlowServer but this annotation is not described in the official documentation anymore - is it still valid?
There is also no way described how I could use any other security then oauth, do I really need to use oauth? how about using my own security config or even only basic authentication?
I kind of expected the same flexibility as spring cloud config server provides...
You can check the Spring Cloud Data Flow site on how to install SCDF on Cloud Foundry. The instructions in this site have the correct information set up SCDF on CF.
The #EnableDataFlowServer is intended for customizing Spring Cloud Data Flow server using/overriding the existing DataFlowServerAutoConfiguration and DataFlowControllerAutoConfiguration. This is not specific to CF though.

How to practice with Spring cloud in local machine?

I am new and just started to explore Spring Cloud. Would like to know how to practice with examples in local (laptop). It appears to need a cloud environment. And most of them are available only for few days. So any pointers to try out features like
Distributed/versioned configuration, Service registration and discovery ,Routing Service-to-service calls, Load balancing Circuit and Breakers Global locks
You can check out the Spring guides where we guide you, step by step, to achieve what you have described. You can check out the link here for the Ribbon guide -
https://spring.io/guides/gs/client-side-load-balancing/ and the link to all of the guides https://spring.io/guides/
You can also check this blog, service discovery, routing and load balancing.
Spring Cloud, Eureka and Zuul
For Distributed/versioned configuration, check this one
Quick Intro to Spring Cloud Configuration
Also one example, that brings all of that together Spring Cloud Bootstrapping

Microservices Config and eureka service which one to start first?

I am creating a simple project in microservices using spring boot and netflix OSS to get my hands dirty. I have created two services
config service which has to register itself in discovery(eureka)
service.
discovery service which requires config service to be running to get its configuration.
Now when I am starting these services, both services fails due to inter dependency. What are the best practices resolve this issue and which one to start first.
PS:- I know I am creating circular dependency, But what is the way to deal with situation like this where I want to keep eureka configuration also with the config server
Thanks
I believe that you can find the answer for your question in the official spring cloud config server documentation:
Here: http://cloud.spring.io/spring-cloud-config/spring-cloud-config.html#_spring_cloud_config_client
Basically you have to choose between a "Config First Bootstrap" or "Discovery First Bootstrap".
From the docs:
"If you are using a `DiscoveryClient implementation, such as Spring Cloud Netflix and Eureka Service Discovery or Spring Cloud Consul (Spring Cloud Zookeeper does not support this yet), then you can have the Config Server register with the Discovery Service if you want to, but in the default "Config First" mode, clients won’t be able to take advantage of the registration.
If you prefer to use DiscoveryClient to locate the Config Server, you can do that by setting spring.cloud.config.discovery.enabled=true (default "false"). The net result of that is that client apps all need a bootstrap.yml (or an environment variable) with the appropriate discovery configuration. (...)"

Zuul proxy that discovers routes dynamically

I have a simple Zuul app that has a single route in the application.yml to route to my microservice. It's working.
However, what I'm looking for is a more dynamic solution where I can wire up routes dynamically, either through code or perhaps by POSTing to some Zuul endpoints during a build (possibly by using springfox and a swagger definition from microservices). I could not find an API for Zuul.
I'm somewhat aware of Eureka and that seems like a solution to abstract away the routing by doing discovery. However, I'm curious if there's a solution without introducing Eureka. If there's a way to wire up these routes in Zuul during a build vs. having to edit the application.yml every time.
Thanks in advance.
If you go for Eureka this will actually work ootb. Zuul as packaged in spring cloud will automatically expose every service using its name. So if you register a service called users in Eureka, Zuul will automatically create a route /users forwarding to the instances by default. That will only allow simple url structures but should solve your problem.
Please see the official documentation for details:
By convention, a service with the ID "users", will receive requests from the proxy located at /users (with the prefix stripped). The proxy uses Ribbon to locate an instance to forward to via discovery, and all requests are executed in a hystrix command, …
I'm actually editing a blog post about this exact topic (Routing and Filtering using Spring Cloud Zuul Server) but the source code has been available and working for some time now. Feel free to use it as a reference:
https://bitbucket.org/asimio/zuulserver
https://bitbucket.org/asimio/discoveryserver (in case routes are configured with serviceIds)
https://bitbucket.org/asimio/demo-config-properties/src (Zuul-Server-refreshable.yml where routes are dynamically updated).
Look at the refreshable Spring profile settings. This Zuul setup works with both, hard-coding routes url or discovered using Eureka.
It also acting as a Spring Cloud Config client so that routes could be dynamically updated via Git, which is also covered in another blog post: Refreshable Configuration using Spring Cloud Config Server, Spring Cloud Bus, RabbitMQ and Git.

Spring cloud config client without Eureka, Ribbon and spring boot

I have spring web application (not spring boot) running in AWS. I am trying to create centralized configuration server. How to refresh the spring-cloud-client after the changing the properties? As per tutorial
Actuator endpoint by sending an empty HTTP POST to the client’s refresh endpoint, http://localhost:8080/refresh, and then confirm it worked by reviewing the http://localhost:8080/message endpoint.
But my aws Ec2 instances are behind the loadbalancer so i can't invoke the client url. I didn't understand the netflix Eureka and Ribbon much but it seems like adding another level of load balancer in the client side. I don't like this approach. Just to change a property i don't want to make the existing project unnecessarily complex. Is there any other way? or Am I misunderstood Eureka/Ribbon usage?
I have looked at the spring-cloud-config-client-without-spring-boot, spring-cloud-config-client-without-auto-configuration none of them have answer. First thread was answered in 2015. Wondering is there any update?
To get the configuration properties from a config server. You can do a http request. Example:
From the documentation we can see:
/{application}/{profile}[/{label}]
/{application}-{profile}.yml <- example
/{label}/{application}-{profile}.yml
/{application}-{profile}.properties
/{label}/{application}-{profile}.properties
So if you would do a request to http://localhost:8080/applicationName-activeProfile.yml you would receive the properties in .yml format for the application with that name and active profile. Spring boot config clients would automatically provide these values but you will have to provide em manually.
You don't need Eureka/Ribbon for this to work, it's a separate component.
More info: http://cloud.spring.io/spring-cloud-static/spring-cloud.html#_spring_cloud_config
Maybe you could even use spring-cloud-config but I'm not sure what extra configuration is needed without spring-boot.
https://cloud.spring.io/spring-cloud-config/

Resources