This project demonstrates communication between microsrvices using:
- RestTemplate (legacy/simple)
- WebClient (Reactive and modern alternative to RestTemplate)
- Fiegn Client (Declarative Rest Client)
spring-microservice-communication-demo/ ├── common-service/ # Common DTOs shared between services ├── user-service/ # Provides user data (like a database service) ├── caller-service/ # Calls user-service using Feign, RestTemplate, and WebClient └── pom.xml # Parent pom
- user-service has a simple REST API that gives user data.
- caller-service tries to get that user data using three different clients: => RestTemplate (traditional synchronous HTTP client) => WebClient (modern reactive/non-blocking client) => Feign (declarative REST client — just write interface, Spring handles the rest)
Contains the User.java DTO (Data Transfer Object). Shared by both caller-service and user-service. No business logic or controllers.
Simulates a real backend service that exposes user-related endpoints.
Provides a dummy user for any given ID. Sample Endpoint: GET http://localhost:8080/user/{id}
Calls the user-service using: 1. RestTemplateUserClient 2. WebClientUserClient 3. FeignUserClient Sample Feign Endpoint (exposed by caller-service): GET http://localhost:8081/feign-client/user/1
- start user-service
- cd user-service
- mvn spring-boot run it runs on port#8080
- start caller-service
- cd caller-service
- mvn spring-boot run it runs on port#8081
GET http://localhost:8081/feign-client/user/1
GET http://localhost:8081/web-client/user/1
GET http://localhost:8081/rest-template/user/1 Each of these calls will return a user fetched from user-service.
{ "id": 1, "name": "abc", "email": "xyz@example.com" }