Microservice Communication Example

This program models communication between microservices.

Problem Statement

Write a Java program where OrderService calls PaymentService.

Source Code

1 class PaymentService {
2 void processPayment(){ System.out.println("Payment processed"); }
3 }
4 class OrderService {
5 PaymentService ps=new PaymentService();
6 void createOrder(){
7 System.out.println("Order created");
8 ps.processPayment();
9 }
10 }
11 public class MicroserviceCommunication {
12 public static void main(String[] args) {
13 System.out.println("Eduinq Microservice Communication");
14 OrderService os=new OrderService();
15 os.createOrder();
16 }
17 }

Program Output

Eduinq Microservice Communication
Order created
Payment processed

Explanation

OrderService communicates with PaymentService. - Demonstrates service interaction in microservices. - This models enterprise workflows across services. Conclusion: Shows microservice communication example.

Quick Links to Explore