Spring Cloud: how to use Feign without registration into Eureka - java

I have a eureka server and some services, they register to the eureka and use a Feign to communicate with each other.
Every of such services is deployed into embedded tomcat container. Also I have some services which are executed as a demons by scheduled, they shouldn't be into tomcat container, but they also have to use a Feign to get data from some services.
By example I have a monitoring which is executed one time per day and checks some data got from another service by REST. That monitoring don't have to register in eureka cause it doesn't have api for input.
If I put #EnableFeignClients without #EnableEurekaClient, it won't work, but
if i put both of these annotations, service will be deployed into tomcat.
How could I do that without tomcat container?

Related

Spring Boot microservice , black list/exclude list of ports

Requirement - Is there any way via configuration/custom logic to provide a blacklist ports configuration so sprint boot service will never pick those ports when it starts, this is required as some of our legacy services runs in dedicated ports and those services starts after our spring boot application starts, if spring boot application picks those ports then it will create a clash.
example : we are looking for something like below , where we can exclude these ports so they will never be picked up by spring boot application.
exclude.ports= 18080,28080

spring boot actuator refreshscope

I have an application which is running on multiple AWS hosts behind a load balancer. All of these instances load the configuration from a spring config server. I can use spring boot admin server to identify the the URL's so that I can execute the POST at hostname:port/actuator/refresh command for individual host using POSTMAN. As the number of hosts increase, it becomes difficult to run a command for each one of the hosts. Is there a way I can do the same with a single command?
We use something similar for our application
i.e Spring applications fetching properties from config server and a spring boot admin server to which all these application registers.
We have exposed an post api in bootadmin which calls refresh endpoint on all instances of specified app.
Since bootadmin has all information about registered apps, we are using it to 'publish' message to all 'subscribed' apps.

How do http requests work in deployed Spring Boot app?

Can someone explain how hosting works ? in my spring boot app there'ss embedded tomcat server. as I understand the spring app runs with tomcat, tomcat takes some port, 8080 for example, and listens to requests coming to that port (when deployed locally at least) localhost:8080. I can make requests from my front end app, which runs on localhost:3000 and tomcat will take the requests, find controllers mapped to the urls that front request is directed to "/user" or "/myposts" or whatever, that controller runs code, talks to db inserts data into response and tomcat sends it back to front end.
If I deploy my app to some hosting service, like Google cloud, does the spring app still run with tomcat ? in that case which port will tomcat run on, where would my front end send requests to ? to the subdomain that google cloud has set up for my project ? Where would i need to configure SSL/https ? Would my front end send secure requests to google subdomain over https endpoints and it would relay those requests to deployed spring app through http(unsecured, inside hosting server) ? Or how ?
One of the most straightforward way to do this is to spin up an instance, ssh into the that instance and run your spring boot app the same way you would run it on your machine. Everything works the same as it would on that cloud instance. Your spring boot app still runs within tomcat and it still listens to port 8080. The only difference is now the hostname is no longer localhost and it will be the DNS name of that instance. You can find the DNS name on the console.
You need to get a SSL certificate if you wanna enable https "natively" in your spring boot app. Alternatively, you can set up a load balancer or an API gateway in front of your cloud instance to do the SSL termination for you. In this case, your frontend will send request to the load balancer or API gateway instead of your spring boot app. They accept https requests and transform them to http request and send it to your spring boot app.

WAR based microservice registration with Eureka Discovery Server

One of our client applications has following architecture -
Angular based front end
Spring Boot based web application to talk to front end
Spring Boot based microservices to talk to web application
Eureka Discovery client to enable web app locate microservices
Recently we faced some issue and want to make one of the microservice to be installed as application under standalone tomcat. Making microservice application main class extend SpringBootServletInitializer, and changing packaging to war helped generate war artifact and it gets deployed on tomcat, as well as registers on Eureka - but its not servicable.
When web application looks up the service via Eureka and invoked any API, it fails. Even invoking service via Postman or directly in browser fails for registered URL. It seems the microservice when exposed as web application under tomcat does not resolve via Eureka. Any suggestions?
Configuration:
Data service - to be deployed as war
spring.application.name=data-service
server.contextPath=/data-service
server.servlet.application-display-name=Data Service
spring.main.banner-mode=log
#server.port=9090
spring.jmx.default-domain=${spring.application.name}
eureka.client.service-url.defaultZone=http://localhost:9098/eureka
eureka.client.register-with-eureka=true
eureka.client.fetch-registry=true
eureka.client.preferSameZoneEureka=true
ribbon.eureka.enabled=true
ribbon.ReadTimeout = 60000
When deployed, it registers with Eureka Discovery with name data-service, but The uri is not a correct one to reach the instance, it happens to be something like
GET http://data-service/query/xxxxx HTTP/1.1
It misses the Tomcat port 8080 and the tomcat context. Manually checking uri
http://localhost:8080/data-service/query/xxxxx
does work.

Microservices in Docker Container

I am using Spring Cloud for Creating Microservice Architecture.
I was using the below feature from the Spring Cloud
Zuul – API gateway service that provides dynamic routing, monitoring, resiliency, security, and more -
Ribbon – Client side load balancer
Feign – Declarative REST client
Eureka – Service registration and discovery
Sleuth – Distributed tracing via logs
Zipkin – Distributed tracing system with request visualization.
Hystrix - Circuit Breaker, Fault Tolerance, Hystrix Dashboard for all API
Now Lets say if I have 100 microservices, then we need 100 servers to maintain each microservices. So I thought of using Kubernetes to solve this issue by deploying each microservices in a separate docker container, so now since Kubernetes takes care of microserivice health check, autoscaling, load-balancing so do I need to again use Ribbon, Eureka and Zuul.
Can anyone please help me on this
Even when you use Spring Cloud, 100 services do NOT mean 100 servers. In Spring Cloud the packaging unit is Spring Boot application and a single server may host many such Spring Boot applications. If you want, you can containerize the Spring Boot applications and other Spring Cloud infrastructure support components. But that is not Kubernetes.
If you move to Kubernetes, you don't need the infrastructure support services like Zuul, Ribbon etc. because Kubernetes has its own components for service discovery, gateway, load balancer etc. In Kubernetes, the packaging unit is Docker images and one or more Docker containers can be put inside one pod which is the minimal scaling unit. So, Kubernetes has a different set of components to manage the Microservices.
Kubernetes is a different platform than Spring cloud. Both have the same objectives. However, Kubernetes has some additional features like self healing, auto-scaling, rolling updates, compute resource management, deployments etc.
Just to add to saptarshi basu's answer, you might want to look at https://dzone.com/articles/deploying-microservices-spring-cloud-vs-kubernetes as it walks through the comparison and asks which responsibilities you might want to be handled by which components when using Spring cloud on kubernetes

Categories