Skip to content

Commit

Permalink
eventstream에서 error를 구독하는 액터 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
심승용 committed May 7, 2020
1 parent 9834697 commit 50d208f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
20 changes: 20 additions & 0 deletions Actors/EventSubscribeActor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Akka.Actor;
using Akka.Event;

namespace BLUECATS.ToastNotifier.Actors
{
public class EventSubscribeActor : ReceiveActor, IWithUnboundedStash
{
public IStash Stash { get; set; }

public static Props Props(IActorRef notificationActor)
{
return Akka.Actor.Props.Create(() => new EventSubscribeActor(notificationActor));
}

public EventSubscribeActor(IActorRef notificationActor)
{
Receive<Error>(m => { notificationActor.Tell(m.ToString()); });
}
}
}
2 changes: 2 additions & 0 deletions Actors/NotificationActor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public NotificationActor(Notifier notifier)
BecomeStacked(Delaying);
});

Receive<string>(m => notifier.ShowError(m));
}

private void Delaying()
Expand Down
6 changes: 3 additions & 3 deletions App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ protected override void OnStartup(StartupEventArgs e)
var fileVersionInfo = FileVersionInfo.GetVersionInfo(assembly.Location);
_version = fileVersionInfo.ProductVersion;



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

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

notificationActor = system.ActorOf(NotificationActor.Props(Notifier), nameof(NotificationActor));
var parserActor = system.ActorOf(ParserActor.Props(notificationActor), nameof(ParserActor));

var eventSubscribeActor = system.ActorOf(EventSubscribeActor.Props(notificationActor), nameof(EventSubscribeActor));
system.EventStream.Subscribe(eventSubscribeActor, typeof(Akka.Event.Error));

var bootStrapServers = GetBootStrapServers(config);

Expand All @@ -91,6 +90,7 @@ protected override void OnStartup(StartupEventArgs e)
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
Current.Shutdown();
}

base.OnStartup(e);
Expand Down

0 comments on commit 50d208f

Please sign in to comment.