Event Workflow Example
This program models workflow using events.
Problem Statement
Write a Java program where OrderCreated event triggers PaymentService.
Source Code
| 1 | interface Subscriber { void update(String event); } |
| 2 | class PaymentService implements Subscriber { |
| 3 | public void update(String event){ |
| 4 | if(event.equals("OrderCreated")) System.out.println("Payment processed for order"); |
| 5 | } |
| 6 | } |
| 7 | class Publisher { |
| 8 | Subscriber sub; |
| 9 | void addSubscriber(Subscriber s){ sub=s; } |
| 10 | void publish(String event){ sub.update(event); } |
| 11 | } |
| 12 | public class EventWorkflow { |
| 13 | public static void main(String[] args) { |
| 14 | System.out.println("Eduinq Event Workflow"); |
| 15 | Publisher p=new Publisher(); |
| 16 | PaymentService ps=new PaymentService(); |
| 17 | p.addSubscriber(ps); |
| 18 | p.publish("OrderCreated"); |
| 19 | } |
| 20 | } |
Program Output
Eduinq Event Workflow Payment processed for order
Explanation
Event triggers workflow. - PaymentService reacts to OrderCreated event. - This models event driven workflows in enterprise systems. Conclusion: Shows event workflow example.