|
11 | 11 | import com.iluwatar.publish.subscribe.subscriber.Subscriber;
|
12 | 12 | import com.iluwatar.publish.subscribe.subscriber.WeatherSubscriber;
|
13 | 13 |
|
| 14 | +/** |
| 15 | + * <p>The Publish and Subscribe pattern is a messaging paradigm used in software architecture with |
| 16 | + * several key points: <li>Decoupling of publishers and subscribers: Publishers and subscribers |
| 17 | + * operate independently, and there's no direct link between them. This enhances the scalability and |
| 18 | + * * modularity of applications.</li><li>Event-driven communication: The pattern facilitates |
| 19 | + * event-driven architectures by allowing publishers to broadcast events without concerning |
| 20 | + * themselves with who receives the events.</li><li>Dynamic subscription: Subscribers can |
| 21 | + * dynamically choose to listen for specific events or messages they are interested in, often by |
| 22 | + * subscribing to a particular topic or channel.</li><li>Asynchronous processing: The pattern |
| 23 | + * inherently supports asynchronous message processing, enabling efficient handling of events and |
| 24 | + * improving application responsiveness.</li><li>Scalability: By decoupling senders and receivers, |
| 25 | + * the pattern can support a large number of publishers and subscribers, making it suitable for |
| 26 | + * scalable systems.</li><li>Flexibility and adaptability: New subscribers or publishers can be |
| 27 | + * added to the system without significant changes to the existing components, making the system |
| 28 | + * highly adaptable to evolving requirements.</li></p> |
| 29 | + * |
| 30 | + * <p>In this example we will create two topics {@link TopicName} WEATHER and CUSTOMER_SUPPORT. |
| 31 | + * then we will register those topics in {@link Publisher} |
| 32 | + * we will create two {@link WeatherSubscriber} to WEATHER {@link Topic} |
| 33 | + * we will create two {@link CustomerSupportSubscriber} to CUSTOMER_SUPPORT {@link Topic} |
| 34 | + * then we will publish the two {@link Topic} with different content in the {@link Message} |
| 35 | + * And we can observe the output in the log where, |
| 36 | + * {@link WeatherSubscriber} publish the message with {@link WeatherContent} |
| 37 | + * {@link CustomerSupportSubscriber} publish the message with {@link CustomerSupportContent} |
| 38 | + * Each subscriber is only listening to the subscribed topic. |
| 39 | + */ |
14 | 40 | public class App {
|
| 41 | + |
| 42 | + /** |
| 43 | + * Program entry point. |
| 44 | + * |
| 45 | + * @param args command line args |
| 46 | + */ |
15 | 47 | public static void main(String[] args) {
|
16 | 48 |
|
17 | 49 | final String weatherSub1Name = "weatherSub1";
|
|
0 commit comments