Skip to content

Commit 50d208f

Browse files
author
심승용
committed
eventstream에서 error를 구독하는 액터 추가
1 parent 9834697 commit 50d208f

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

Actors/EventSubscribeActor.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Akka.Actor;
2+
using Akka.Event;
3+
4+
namespace BLUECATS.ToastNotifier.Actors
5+
{
6+
public class EventSubscribeActor : ReceiveActor, IWithUnboundedStash
7+
{
8+
public IStash Stash { get; set; }
9+
10+
public static Props Props(IActorRef notificationActor)
11+
{
12+
return Akka.Actor.Props.Create(() => new EventSubscribeActor(notificationActor));
13+
}
14+
15+
public EventSubscribeActor(IActorRef notificationActor)
16+
{
17+
Receive<Error>(m => { notificationActor.Tell(m.ToString()); });
18+
}
19+
}
20+
}

Actors/NotificationActor.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ public NotificationActor(Notifier notifier)
4444

4545
BecomeStacked(Delaying);
4646
});
47+
48+
Receive<string>(m => notifier.ShowError(m));
4749
}
4850

4951
private void Delaying()

App.xaml.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ protected override void OnStartup(StartupEventArgs e)
5555
var fileVersionInfo = FileVersionInfo.GetVersionInfo(assembly.Location);
5656
_version = fileVersionInfo.ProductVersion;
5757

58-
59-
6058
var config = AkkaHelper.ReadConfigurationFromHoconFile(Assembly.GetExecutingAssembly(), "conf")
6159
.WithFallback(ConfigurationFactory.FromResource<ConsumerSettings<object, object>>("Akka.Streams.Kafka.reference.conf"));
6260

@@ -68,7 +66,8 @@ protected override void OnStartup(StartupEventArgs e)
6866

6967
notificationActor = system.ActorOf(NotificationActor.Props(Notifier), nameof(NotificationActor));
7068
var parserActor = system.ActorOf(ParserActor.Props(notificationActor), nameof(ParserActor));
71-
69+
var eventSubscribeActor = system.ActorOf(EventSubscribeActor.Props(notificationActor), nameof(EventSubscribeActor));
70+
system.EventStream.Subscribe(eventSubscribeActor, typeof(Akka.Event.Error));
7271

7372
var bootStrapServers = GetBootStrapServers(config);
7473

@@ -91,6 +90,7 @@ protected override void OnStartup(StartupEventArgs e)
9190
catch (Exception ex)
9291
{
9392
MessageBox.Show(ex.ToString());
93+
Current.Shutdown();
9494
}
9595

9696
base.OnStartup(e);

0 commit comments

Comments
 (0)