spring boot ms weather app mini project
spring boot ms weather app mini project
-------------------------------------------
Run ms1:
--------
wservice: 8082
wclient: 8085
Eureka server: 8070
api gateway: 8072
step 1: k8s local setup using docker desktop and k8s dashboard
--------------------------------------------------------
Step 2: create docker images of wservice, wclient and push to docker hub
---------------------------------------------------------------------------
Step 1.1: add jibs plugin to every project and give correct name
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>3.3.2</version>
<configuration>
<from>
<image>eclipse-temurin:21-jre</image>
</from>
<to>
<image>rgupta00/${project.artifactId}:v1</image>
</to>
</configuration>
</plugin>
--------------------------------------------
ms2
-----------------------------------------
2. url pattern
http://localhost:8070/
check
http://localhost:8070/eureka/app
6. now replace hard coded url in Openfeign service to logical names and run the
examples
give logical name of service
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
application.yml
--------------------
server:
port: 8072
spring:
application:
name: gateway
eureka:
instance:
prefer-ip-address: true
client:
register-with-eureka: true
fetch-registry: true
service-url:
defaultZone: http://localhost:8070/eureka/
management:
endpoints:
web:
exposure:
include: "*"
health:
readinessstate:
enabled: true
livenessstate:
enabled: true
endpoint:
gateway:
enabled: true
health:
probes:
enabled: true
@Configuration
public class RouteConfig {
@Bean
public RouteLocator busycoderRouteConfig(RouteLocatorBuilder
routeLocatorBuilder) {
return routeLocatorBuilder.routes()
.route(p -> p
.path("/weathermgt/wc/**")
.filters( f -> f.rewritePath("/weathermgt/wc/(?
<segment>.*)",
"/${segment}")
.addResponseHeader("X-Response-Time",
LocalDateTime.now().toString()))
.uri("lb://WCLIENT"))
.route(p -> p
.path("/weathermgt/ws/**")
.filters( f -> f.rewritePath("/weathermgt/ws/(?
<segment>.*)","/${segment}")
.addResponseHeader("X-Response-Time",
LocalDateTime.now().toString()))
.uri("lb://WSERVICE"))
.build();
}
}
@Component
public class LoggingFilter implements GlobalFilter {
private Logger logger = LoggerFactory.getLogger(LoggingFilter.class);
@Override
public Mono<Void> filter(ServerWebExchange exchange,
GatewayFilterChain chain) {
logger.info("Path of the request received -> {}",
exchange.getRequest().getPath());
return chain.filter(exchange);
}
}