Skip to content

Commit

Permalink
EventStream deadLetters doc has been improved (#6662)
Browse files Browse the repository at this point in the history
* 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 <aaron@petabridge.com>
  • Loading branch information
F0b0s and Aaronontheweb authored Apr 24, 2023
1 parent 7c2ace9 commit fd4860b
Showing 1 changed file with 87 additions and 0 deletions.
87 changes: 87 additions & 0 deletions docs/articles/utilities/event-bus.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ title: Event Bus
---
# EventBus

EventBus provides several types of custom messages to subscribe to:

1. `DeadLetter` - messages that are not delivered to actor
2. `UnhandledMessage` - messages which actor receives and doesn't understand
3. `SuppressedDeadLetter` - similar to DeadLetter with the slight twist of NOT being logged by the default dead letters listener
4. `Dropped` - messages dropped due to overfull queues or routers with no routees
5. `AllDeadLetters` - shortcut for all types of unhandled messages

## Subscribing to Dead Letter Messages

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.
Expand Down Expand Up @@ -58,6 +66,85 @@ sample capture
DeadLetter captured: another message, sender: [akka://MySystem/deadLetters], recipient: [akka://MySystem/user/ExpendableActor#1469246785]
```

## Subscribing to Unhandled Messages

The following example demonstrates the capturing of unhandled messages. The dedicated actor will output captured unhandled message to the console.

```csharp
public class DumbActor : ReceiveActor { }

public class UnhandledMessagesMonitorActor : ReceiveActor
{
public UnhandledMessagesMonitorActor()
{
Receive<UnhandledMessage>(Console.WriteLine);
}
}

using (var system = ActorSystem.Create("MySystem"))
{
var dumbActor = system.ActorOf<DumbActor>();
var monitorActor = system.ActorOf<UnhandledMessagesMonitorActor>();

// Subscribe to messages of type UnhandledMessage
system.EventStream.Subscribe(monitorActor, typeof(UnhandledMessage));

// try sending a message to actor which it doesn't understand
dumbActor.Tell("Hello");

Console.ReadLine();
}
```

sample capture

```string
DeadLetter from [akka://MySystem/deadLetters] to [akka://MySystem/user/$a#965879198]: <Hello>
```

## Subscribing to AllDeadLetters Messages

The following example demonstrates the capturing of all unhandled messages types. The dedicated actor will output captured unhandled messages to the console.

```csharp
public class DumbActor : ReceiveActor { }

public class AllDeadLettersMessagesMonitorActor : ReceiveActor
{
public AllDeadLettersMessagesMonitorActor()
{
Receive<AllDeadLetters>(Console.WriteLine);
}
}

using (var system = ActorSystem.Create("MySystem"))
{
var dumbActor = system.ActorOf<DumbActor>();
var monitorActor = system.ActorOf<AllDeadLettersMessagesMonitorActor>();

// Subscribe to messages of type AllDeadLetters
system.EventStream.Subscribe(monitorActor, typeof(AllDeadLetters));

// try sending a message to actor which it doesn't understand
dumbActor.Tell("Hello");

// simulate the actor failing/stopping
dumbActor.Tell(Akka.Actor.PoisonPill.Instance);

// try sending a message to the stopped actor
dumbActor.Tell("world");

Console.ReadLine();
}
```

sample capture

```string
DeadLetter from [akka://MySystem/deadLetters] to [akka://MySystem/user/$a#1479030912]: <Hello>
DeadLetter from [akka://MySystem/deadLetters] to [akka://MySystem/user/$a#1479030912]: <world>
```

## Subscribing to Messages of Type `string`

```csharp
Expand Down

0 comments on commit fd4860b

Please sign in to comment.