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.
Related
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.
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.
I have created a Spring Boot microservice and hosted inside a Tomcat on a Linux machine.
Everything is inside the container and the container is inside the IBM cloud private platform.
Now the microservice should be running continuously.
But suppose for any reasons the microservice got stop or tomcat got crashed.
Is there any way we could restart the Tomcat server or microservice automatically without manual intervention?
Why are you deploying a Spring boot app in your local tomcat? By default Springboot comes with embedded Tomcat server in it, so if you just build and run the jar, a tomcat will be started with the service itself.You can also , configure the server type(tomcat or jetty) and other server properties in the application.yml file. More details here - https://www.springboottutorial.com/spring-boot-with-embedded-servers-tomcat-jetty
Coming to the second part, of the question,about how to make sure , that if one service crashes, a new instance should be started automatically, for this you might be needing to do some reading on container managers like dockerswarm or kubernetes, which support auto-scaling, and can take care of restarting services (pods) as and when required,they can even scale up, meaning increase the number of instances of a service if existing containers reach a resource usage threshold and then load balancing requests to that service through some discovery and registry client.I think this would be helpful to you - https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#restart-policy
I've got a simple SPA Sprint Boot application - executable jar with embedded tomcat and looking to plug it into siteminder with preauthenticatedauthenticationprovider. Application is http://someserver:1234
Documentation states that a WebAgent is installed on a web server and that 'intercepts' requests. Would the WebAgent be deployed in a separate container? If so, how does it intercept requests? All documentation refers to this intercept, but doesn't state the mechanism.
Does it need to be deployed inside the same container to intercept requests? The only way I can think any http headers are intercepted is through proxies.
There are 2 ways to configure Web Agent.
1. Local Configuration
- Setup Agent in the sever where Applciaiton is hosted.
2. Centralized Configuration
- Setup Agent in the a web server like Apache and add proxy entries to the backend applications. this configuration intercepts each and every request going from the webagent server. I recommend this. if you have still questions drop here.
- Thanks,
Chiranjeevi
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?