You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: poison-pill/README.md
+31-73Lines changed: 31 additions & 73 deletions
Original file line number
Diff line number
Diff line change
@@ -10,58 +10,31 @@ tags:
10
10
---
11
11
12
12
## Intent
13
-
Poison Pill is known predefined data item that allows to provide graceful shutdown for separate distributed consumption
14
-
process.
13
+
14
+
Poison Pill is known predefined data item that allows to provide graceful shutdown for separate
15
+
distributed consumption process.
15
16
16
17
## Explanation
17
18
18
19
Real world example
19
20
20
-
> Let's think about a message queue with one producer and one consumer. The producer keeps pushing new messages in the queue and the consumer keeps reading them. Finally when it's time to gracefully shut down the producer sends the poison pill message.
21
+
> Let's think about a message queue with one producer and one consumer. The producer keeps pushing
22
+
> new messages in the queue and the consumer keeps reading them. Finally when it's time to
23
+
> gracefully shut down the producer sends the poison pill message.
21
24
22
25
In plain words
23
26
24
27
> Poison Pill is a known message structure that ends the message exchange.
25
28
26
29
**Programmatic Example**
27
30
28
-
Let's define the message structure first.
31
+
Let's define the message structure first. There's interface `Message` and implementation
32
+
`SimpleMessage`.
29
33
30
34
```java
31
35
publicinterfaceMessage {
32
36
33
-
MessagePOISON_PILL=newMessage() {
34
-
35
-
@Override
36
-
publicvoidaddHeader(Headersheader, Stringvalue) {
37
-
throw poison();
38
-
}
39
-
40
-
@Override
41
-
publicStringgetHeader(Headersheader) {
42
-
throw poison();
43
-
}
44
-
45
-
@Override
46
-
publicMap<Headers, String>getHeaders() {
47
-
throw poison();
48
-
}
49
-
50
-
@Override
51
-
publicvoidsetBody(Stringbody) {
52
-
throw poison();
53
-
}
54
-
55
-
@Override
56
-
publicStringgetBody() {
57
-
throw poison();
58
-
}
59
-
60
-
privateRuntimeExceptionpoison() {
61
-
returnnewUnsupportedOperationException("Poison");
62
-
}
63
-
64
-
};
37
+
...
65
38
66
39
enumHeaders {
67
40
DATE, SENDER
@@ -110,7 +83,9 @@ public class SimpleMessage implements Message {
110
83
}
111
84
```
112
85
113
-
Next we define the types related to the message queue.
86
+
To pass messages we are using message queues. Here we define the types related to the message queue:
87
+
`MqPublishPoint`, `MqSubscribePoint` and `MessageQueue`. `SimpleMessageQueue` implements all these
88
+
interfaces.
114
89
115
90
```java
116
91
publicinterfaceMqPublishPoint {
@@ -146,29 +121,15 @@ public class SimpleMessageQueue implements MessageQueue {
146
121
}
147
122
```
148
123
149
-
Now we need to create the message producer and consumer.
124
+
Next we need message `Producer` and `Consumer`. Internally they use the message queues from above.
125
+
It's important to notice that when `Producer` stops, it sends out the poison pill to inform
0 commit comments