2017-04-23 2 views
1

Je suis nouveau sur Akka.NET. J'ai récemment commencé à faire mon projet d'université et fait face à l'étrange problème. J'ai deux ActorSystems dans deux applications de bureau différentes. Dans le premier ActorSystem, j'envoie le message ZippedAddressListMessage entre deux acteurs en utilisant Akka.Remote.Akka.NET: impossible d'envoyer un message de liste à d'autres ActorSystem

public class ZippedAddressListMessage 
    { 
     public ZippedAddressListMessage(List<string> list) 
     { 
      this.Values = list.AsReadOnly(); 
     } 

     public IReadOnlyCollection<string> Values { get; private set; } 

    } 

Cela fonctionne très bien, mais lorsque je tente d'envoyer ce message à d'autres ActorSystem, je reçois la grande liste des erreurs: screenshot #1 of the console window with the error

Néanmoins, si j'envoie un message simple qui se compose d'un seul Entier, tout fonctionne bien. Il est probable qu'il y ait un problème de sérialisation, mais je ne pouvais pas comprendre comment cela devait être résolu. J'ai cherché partout, mais je n'ai toujours pas trouvé la réponse. S'il vous plaît, pourriez-vous m'expliquer comment résoudre ce problème?

Acteur de la première ActorSystem:

using Akka.Actor; 
    using System; 
    using System.Collections; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Text; 
    using System.Threading.Tasks; 
    using ChatMessages; 
    using System.Diagnostics; 
    using Akka.Serialization; 
    using Akka.Actor.Internal; 
    using Akka.Remote; 

namespace Agent 
{ 
    public class ActorHelper: ReceiveActor 
    { 
     int N; 
     int fromId; 
     int count; 
     IActorRef chiefAgent; 
     List<recordItem> agentList; 
    public ActorHelper() 
    { 
     count = 0; 
     agentList = new List<recordItem>(); 

     Receive<CreateHelpersMessage>(msg => 
     { 
      chiefAgent = Sender; 
      fromId = msg.fromID; 
      N = msg.N; 

      for (int i = 0; i < msg.N; i++) 
      { 
       Process.Start("C:\\Users\\Artemij\\Source\\Repos\\Client\\AgentHelper\\AgentHelper\\bin\\Debug\\AgentHelper.exe", 
           "akka.tcp://[email protected]:8000/user/AgentActor/ActorHelper" + " " + i); 
      } 

     }); 


     Receive<NewAgentHelperMessage>(msg => 
     { 
      Console.WriteLine(msg.name + " " + Sender.Path.ToString() + " || " + (count+1) + "/" + N); 
      agentList.Add(new recordItem(fromId + count, msg.name, Sender)); 
      count++; 

      Context.Watch(Sender); 

      if (count == N) 
      { 
       chiefAgent.Tell(new AddressListMessage(agentList), Self); 

      } 


     }); 

     Receive<AddressListMessage>(msg => 
     { 
      Console.WriteLine("All is ready"); 
      List<string> temp = new List<string>(); 
      foreach (recordItem i in msg.Values) 
      { 
       temp.Add(i.ID + " " + i.name + " " + Serialization.SerializedActorPath(i.address)); 
      } 

      foreach (recordItem i in agentList) 
      { 
       Console.WriteLine(i.address); 

       //PROBLEM HERE! 
       i.address.Tell(new ZippedAddressListMessage(temp), Self); 

      } 



     }); 




    } 

} 

}

Acteur d'autres ActorSystem:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using Akka.Actor; 
using ChatMessages; 
using System.Diagnostics; 

namespace AgentHelper 
{ 

class AgentHelperActor: ReceiveActor 
{ 
    int priority; 
    ActorSelection seniorAgentActor;  
    List<recordItem> fullList; 


    public AgentHelperActor(string addressSenior, string rank) 
    { 
     fullList = new List<recordItem>(); 

     seniorAgentActor = Context.ActorSelection(addressSenior); 
     Int32.TryParse(rank, out priority); 

     seniorAgentActor.Tell(new NewAgentHelperMessage("agent"+priority, ""), Self); 

     //RECEIVING A LIST!! 
     Receive<ZippedAddressListMessage>(msg => 
     { 
      Console.WriteLine("The entire list"); 


     }); 


     Receive<NewAgentHelperMessage>(msg => 
     { 
      Console.WriteLine(msg.name); 

     }); 


    } 


    public void updateList(IReadOnlyCollection<recordItem> list) 
    { 
     fullList = new List<recordItem>(list); 
     foreach (recordItem i in fullList) 
     { 
      Console.WriteLine(i.ToString()); 
     } 
    } 


} 

}

MISE À JOUR: Voici une capture d'écran de l'erreur au début. screenshot #2 of the console window with the error Il écrit que le format de System.String [] n'est pas compatible avec la sérialisation JSON.

Répondre

0

Le problème a été résolu! Le problème concernait le sérialiseur: j'utilisais le sérialiseur Newtonsoft.Json. Quand il s'agit d'envoyer un message à un ActorSystem distant, il ne peut pas sérialiser la liste. Newtonsoft explique que System.String [] est un type incompatible.

La solution est d'installer Hyperion sérialiseur: http://getakka.net/docs/Serialization#how-to-setup-wire-as-default-serializer