Example of Sidecar Application for Microservices - spring

Is Spring cloud config server an example of sidecar application for microservices?

Do you mean if the Spring Cloud Config Server itself is what the Spring Cloud documentation labels as Sidecar? Then no, as far as I know it is just a plain, regular Spring Boot app.
A Sidecar as referred to in Polyglot support with Sidecar is a Spring Boot application that acts as a bridge between your service infrastructure and a service that is not written in a JVM language. Apps written in Python, Go, Ruby, C#, NodeJS, Erlang or really any other language that can bind something to a port come to mind.
The benefits of the Sidecar are, that your Non-JVM apps
service discovery become automatically discoverable through Eureka, which means that JVM services can resolve the host:port/<service-id> of the Non-JVM apps as well as the other way around,
monitoring are monitorable through the same health-endpoints-infrastructure that is available in Spring Boot (Actuator), i.e. by manually providing the health endpoint in the Non-JVM app Eureka knows when the Non-JVM service is down
routing/proxying query the services by either manually looking up their hosts/ports or proxying these requests through Zuul, which in turn resolves their current addresses through Eureka
balancing be load balanced by Ribbon and
configuration may consume configuration properties provided via Spring Cloud Config.
I hope this answer addresses your question, if not (or someone finds it to be inaccurate or misleading) just let me know and I delete it to make room for something more suitable. ;-)

Related

Recommended/Alternative ways of starting a Spring Boot app if config server is down?

Was wondering the recommended way of starting a spring boot app if the Spring cloud config server is temporarily down or unavailable. What would be the approach? I know of the retry configurations, but I am wondering if there is a way to have a 'replica' config server and use that as a failover (or something along those lines).
Sure, why not?
After all, spring-cloud-config server exposes rest API and all the interaction with spring boot microservices is done over HTTP.
From this point of view, you can scale out the spring cloud config server by providing more than one instance of it all are up-and-running and mapping them to one virtual IP.
If you're running in some kind of orchestrated environment (like kubernetes) it is a very easy thing to do.

How we configure API gateway, service discovery for micro services in pcf?

I am learning building microservices using spring boot, Spring Cloud(netflix OSS Components). I have used netflix Eureka for service discovery, zuul for api gateway, ribbon, feign while running in my local machine.
Netflix eureka, zuul, ribbon, feign spring cloud config are not useful when we deploy to PCF?(if yes what are the alternatives available in pcf and how to configure them?)
As who are building microservices follows CI/CD approach, how developer verify working of their micro services before pushing code as we don't use eureka, zuul,ribbon,feign in production pcf. (how to simulate pcf environment in developer machine?).
I'd suggest to read below content before implementing if you have any doubt regarding usage of Eureka and Zuul, you will get all answers yourself.
https://github.com/Netflix/eureka/wiki/Eureka-at-a-glance
https://github.com/Netflix/zuul/wiki
As who are building microservices follows CI/CD approach, how developer verify working of their micro services before pushing code as we don't use eureka, zuul,ribbon,feign in production pcf.
Answer to this question is: You must be aware of JUnit test cases, so you can run you test cases using deployment pipelines to make sure all your functionalities are working as expected or you can use Test Automation for the same.
(how to simulate pcf environment in developer machine?).
Answer to this one:
You can use eclipse plugin you are using eclipse/STS IDE. Or you can connect all PCF services from you local machine using CloudFactory
#Bean
public Cloud cloud() {
return new CloudFactory().getCloud();
}
https://docs.pivotal.io/pivotalcf/2-1/buildpacks/java/sts.html
Here are some thoughts:
Eureka Service discovery: in my opinion this is not strictly necessary when running on PCF. When you push an app on PCF usually a route is assigned to your app, and you can use this Route as a poor man's service discovery. Eureka would allow you to use client-side load balancing in the case of container-to-container networking, but usually you wouldn't need this.
Zuul: Can be very useful also on CloudFoundry in case you are doing things like writing frontend-for-backend services, providing frontends for different devices (mobiles, desktops, i-pads) that use the same backend services. Might also be useful for an authentication/authorization layer or rate-limiting. One native CloudFoundry alternative would be to use route-services for tasks such as rate limiting, authentication/authorization.
spring-cloud-config: makes sense if you want your configuration to be under version control for different environments. This is useful no matter if you are running on CloudFoundry or not. I don't know of any alternatives on plain CloudFoundry.
spring-cloud-feign: makes sense if you want use annotations such as #RequestMapping with your Feign client interfaces. This is independent on if you are running on CloudFoundry or not. AFAIK there are no alternatives for this in case you want to use Spring MVC annotations with Feign.
ribbon: makes sense if you want to use client side load balancing as opposed to let the CloudFoundry router to do the load balancing for you.
How developers can check locally if this works for them:
In general, I don't believe developers should need to check locally if their app is working fine together with zuul, cloud-config-service, and eureka.
They could check this in a dev or test space or environment though.
If they really want to check this on their local machine, they could download PCFDev and run these infrastructure components there.
Hope this helps.

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. (...)"

Creating a Client/Service in Netflix Eureka

With regards to the Netflix Eureka Service Registry, I have setup the Eureka Netflix Server using Tomcat 8.0.35 successfully. I have also got the basic Example Service & Client to communicate with each other. I'm still new to Eureka and the management decision is to use Eureka with Spring as several new applications are written around the Spring framework.
I have been following the wiki in order to understand how the communication works (But with little to no success with registering services).. Eureka Github Wiki.
My question is: Do I need to create my own Eureka Service & Client in order to maintain a registry of about 50 cloud instances? (If so, can you please point me in the right direction).
I have hands on experience with Consul/RESTfull API, and have implemented Consul in production (using php, and qbit); however the Netflix Eureka Registry look's as though I need to learn eureka/spring + client/server java programming? I'm still getting used to the following terms.
Eureka Server (I successfully got this working using Tomcat8/JDK1.8 + the eureka.war)
Eureka Service (Some kind of stand-alone RESTfull service that queries the Eureka-Server and listens for client requests)
Eureka Client (Java snippet to be embedded into the Java servlets/jsp)?
Zuul (A type of routing/load-balancing app - similar to HaProxy ?)
Ribbon (A type of routing/load-balancing app - similar to HaProxy ?)
I would like to get the Service & Client configured for mostly non-AWS cloud instances. The Eureka Wiki is not very helpful when it comes to creating a working eureka service & client. Any help to point me in the right direction to implement a Eureka based RESTfull system would be helpful.
I suggest you to read this documentation about spring-cloud : http://cloud.spring.io/spring-cloud-static/spring-cloud.html
It should be a good start to setup a few simple spring-boot/spring-cloud services and start to use advanced tools like zuul/ribbon/hystrix ...
There is a simple example of distributed system using Spring Boot and Spring Cloud Netflix.
This project contains the following microservices:
requestor and responder which communicates via REST/HTTP
gateway microservice - Spring Boot app + Zuul
discovery microservice - Spring Boot app + Eureka
Moreover, requestor microservice uses Hystrix library.
As you can see, Spring Cloud provides a really good wrapper for Netflix solutions. As a result, you can start quickly with minimal configuration.

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