How to practice with Spring cloud in local machine? - spring

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

Related

When to use spring cloud like Eureka discovery,Ribbon etc if we have the same while we deployed the application in K8s?

We have load balancing, discovery, etc in the Spring cloud. But the same load balancing, discovery is available in Kubernetes as well. So just wanted to know when we should go with Spring cloud (load balancing or discovery) and when to use Kubernetes
It depends on your use-case. There can be situations where you need to directly use Eureka server registry and Eureka client discovery offered by Spring Cloud Netflix. Ribbon is the client side load balancer provided by Spring Cloud Netflix.
In my experience, it is not impossible to use Eureka in any environment. It can be your local data centre or cloud infrastructure. However when it comes to deployment environment, there are so many alternatives for us to achieve the server registry mechanism. Sometimes those alternatives are the best solutions. I will give you an example below...
If you host your application in your local server (Local data centre)
Now in this scenario you can use Eureka and continue your server registry and discovery mechanism. (That is not the only way. I mentioned Eureka for this scenario because it would be a good use case for it)
If you host your application in AWS infrastructure
The AWS environment gives you lots of benefits and services such that you can forget the burden of maintaining and implementing Eureka. You can achieve simply the same behaviour by AWS load balancers, AWS target groups and even more by adding AWS auto scaling groups. In AWS it self there are so many other ways to achieve this as well.
Long story in short that for your scenario, you can continue using the power of Kubernetes and get the privilege unless you have a specific reason to use Eureka and put a large effort to implement it. You should select what suits the best depending on time, effort, maintainability, performance etc.
Hope this helps for you to get an idea. Happy coding!

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.

Netflix Archaius with Spring Cloud Config server

I followed this documentation for Archaius and some other online articles. However, presumably, each service should have Archaius or configuration related codes/dependencies(-jars) to load configuration values. My concern is that if a change is required in loading configuration, then each service has to be reloaded/redeployed.
Q1. Can anyone let me know how to keep a centralized Archaius configuration service so that client services pull configurations.
On the contrary, Spring Cloud Config server does that job - all configurations are in one place. But I feel that it lacks loading configurations from a custom resource - data loads from a database as Archaius provides, for example.
Q2. Is there a work around to make Config Server loads configurations from Archaius ?
For Q1, you should look at the 2.x branch of Archaius, specifically https://github.com/Netflix/archaius/blob/2.x/archaius2-persisted2/src/main/java/com/netflix/archaius/persisted2/Persisted2ConfigProvider.java. This is configured to make a rest call to some service which will front your Config. At Netflix, we have a rest service backed by Cassandra. Naturally, you can back that with whatever you would like. But fair warning, this Archaius setup was made for Guice and requires a bit of manual setup. It is not quite as seamless as you might expect if you've been working with Spring Boot/Cloud starters for example.
For Q2, Spring Cloud Config does indeed support loading data from a DB. Also, in my experience with the Spring products, they are almost always quite easy to extend to your own purposes if you'd like to do something more custom.
General suggestion: If you have no other need/use of Archaius aside from remote config and you are a Spring user, I'd suggest just going with Spring Cloud. It would be far easier to configure and probably serve your requirements just fine.
Archaius provides a way to deal with reading dynamically changing Config with minimal performance impact. If you're not in Spring, or happen to need fast access to dynamic properties, consider Archaius.

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

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.

How to do service discovery for Spring Boot REST endpints

If I have multiple Spring Boot embedded tomcat containers and each can have service endpoints like
http://localhost:8080/employeeSelfService/getDetails
http://localhost:8081/employeeSelfService/getDetails
How can do load balancing using 2 micro services such that clients can hit any of the URL's mentioned based on some load balancing startegy
One option thats come to my mind is to use NetFlix Curator (or) have a apache webserver acting as reverse proxy but with apache, when you create new instances of your services, you will have have an entry of that service as a member in httpd.conf
Does Spring Boot provides any service discovery and load balancing mechanism ?
Spring Boot does not provide this feature, as it is already usually provided by a reverse proxy such as apache/nginx running in front of the Spring Boot server.
See here for an example here how the commercial version of nginx provides the functionality of dynamically scaling and reducing the upstream nodes.
So in this case it's for the dynamic instance, in this case the Spring Boot process to signal it's presence/unregister itself to the upstream server at initialization/shutdown.
See here how to do so in the case of nginx, this procedure will be different from server to server.
Arguably it's not really an application's role to manage its own load-balancing, and Spring Boot focuses on the implementation of an application (or service, equivalently). We have been thinking about whether we could provide features in Spring (Boot or otherwise) to make it easy to write your own load-balancer, or service registry app, but even then I don't think that was what the question was really about (or was it?).
If I interpret the question, and the example use case, literally, I would say that the most natural answer is an out-of-the-box reverse proxy solution (as the other answers pointed out). I also note that such a reverse proxy is an essential and natural part of a PaaS solution, so if you need it to "just work" and don't want to know about the details, PaaS would be a natural path (e.g. see cloudfoundry as an example of such a solution that I happen to have worked on).
Indeed Spring Boot has not inherit support for load-balancing. Just to add to the list of available solutions for load-balancing, here are the instructions to configure an Apache for load-balancing.

Resources