Skip to content

Commit fd4860b

Browse files
F0b0sAaronontheweb
andauthored
EventStream deadLetters doc has been improved (#6662)
* Documentation of EventStream unhandled messages notification has been improved (#5334). * Fix after review. * Fix after review. * Update event-bus.md --------- Co-authored-by: Aaron Stannard <[email protected]>
1 parent 7c2ace9 commit fd4860b

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed

docs/articles/utilities/event-bus.md

+87
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ title: Event Bus
44
---
55
# EventBus
66

7+
EventBus provides several types of custom messages to subscribe to:
8+
9+
1. `DeadLetter` - messages that are not delivered to actor
10+
2. `UnhandledMessage` - messages which actor receives and doesn't understand
11+
3. `SuppressedDeadLetter` - similar to DeadLetter with the slight twist of NOT being logged by the default dead letters listener
12+
4. `Dropped` - messages dropped due to overfull queues or routers with no routees
13+
5. `AllDeadLetters` - shortcut for all types of unhandled messages
14+
715
## Subscribing to Dead Letter Messages
816

917
The following example demonstrates the capturing of dead letter messages generated from a stopped actor. The dedicated actor will output the message, sender and recipient of the captured dead letter to the console.
@@ -58,6 +66,85 @@ sample capture
5866
DeadLetter captured: another message, sender: [akka://MySystem/deadLetters], recipient: [akka://MySystem/user/ExpendableActor#1469246785]
5967
```
6068

69+
## Subscribing to Unhandled Messages
70+
71+
The following example demonstrates the capturing of unhandled messages. The dedicated actor will output captured unhandled message to the console.
72+
73+
```csharp
74+
public class DumbActor : ReceiveActor { }
75+
76+
public class UnhandledMessagesMonitorActor : ReceiveActor
77+
{
78+
public UnhandledMessagesMonitorActor()
79+
{
80+
Receive<UnhandledMessage>(Console.WriteLine);
81+
}
82+
}
83+
84+
using (var system = ActorSystem.Create("MySystem"))
85+
{
86+
var dumbActor = system.ActorOf<DumbActor>();
87+
var monitorActor = system.ActorOf<UnhandledMessagesMonitorActor>();
88+
89+
// Subscribe to messages of type UnhandledMessage
90+
system.EventStream.Subscribe(monitorActor, typeof(UnhandledMessage));
91+
92+
// try sending a message to actor which it doesn't understand
93+
dumbActor.Tell("Hello");
94+
95+
Console.ReadLine();
96+
}
97+
```
98+
99+
sample capture
100+
101+
```string
102+
DeadLetter from [akka://MySystem/deadLetters] to [akka://MySystem/user/$a#965879198]: <Hello>
103+
```
104+
105+
## Subscribing to AllDeadLetters Messages
106+
107+
The following example demonstrates the capturing of all unhandled messages types. The dedicated actor will output captured unhandled messages to the console.
108+
109+
```csharp
110+
public class DumbActor : ReceiveActor { }
111+
112+
public class AllDeadLettersMessagesMonitorActor : ReceiveActor
113+
{
114+
public AllDeadLettersMessagesMonitorActor()
115+
{
116+
Receive<AllDeadLetters>(Console.WriteLine);
117+
}
118+
}
119+
120+
using (var system = ActorSystem.Create("MySystem"))
121+
{
122+
var dumbActor = system.ActorOf<DumbActor>();
123+
var monitorActor = system.ActorOf<AllDeadLettersMessagesMonitorActor>();
124+
125+
// Subscribe to messages of type AllDeadLetters
126+
system.EventStream.Subscribe(monitorActor, typeof(AllDeadLetters));
127+
128+
// try sending a message to actor which it doesn't understand
129+
dumbActor.Tell("Hello");
130+
131+
// simulate the actor failing/stopping
132+
dumbActor.Tell(Akka.Actor.PoisonPill.Instance);
133+
134+
// try sending a message to the stopped actor
135+
dumbActor.Tell("world");
136+
137+
Console.ReadLine();
138+
}
139+
```
140+
141+
sample capture
142+
143+
```string
144+
DeadLetter from [akka://MySystem/deadLetters] to [akka://MySystem/user/$a#1479030912]: <Hello>
145+
DeadLetter from [akka://MySystem/deadLetters] to [akka://MySystem/user/$a#1479030912]: <world>
146+
```
147+
61148
## Subscribing to Messages of Type `string`
62149

63150
```csharp

0 commit comments

Comments
 (0)