public void Connect() { var actors = new Dictionary <string, EventConsumerGrain>(); foreach (var consumer in consumers) { var actor = factory.CreateAsync <EventConsumerGrain>(consumer.Name).Result; actors[consumer.Name] = actor; actor.Activate(consumer); } subscriptions.Add(pubSub.Subscribe <StartConsumerMessage>(m => { if (actors.TryGetValue(m.ConsumerName, out var actor)) { actor.Start(); } })); subscriptions.Add(pubSub.Subscribe <StopConsumerMessage>(m => { if (actors.TryGetValue(m.ConsumerName, out var actor)) { actor.Stop(); } })); subscriptions.Add(pubSub.Subscribe <ResetConsumerMessage>(m => { if (actors.TryGetValue(m.ConsumerName, out var actor)) { actor.Reset(); } })); subscriptions.Add(pubSub.ReceiveAsync <GetStatesRequest, GetStatesResponse>(request => { var states = actors.Values.Select(x => x.GetState()).ToArray(); return(Task.FromResult(new GetStatesResponse { States = states })); })); }