Akka.NET:无法发送列表消息给其他演员系统

问题描述:

我是Akka.NET的新手。我最近开始做我的大学项目并面临奇怪的问题。 我在两个不同的桌面应用程序中有两个ActorSystems。在第一个ActorSystem中,我使用Akka.Remote在两个演员之间发送消息ZippedAddressListMessage。Akka.NET:无法发送列表消息给其他演员系统

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

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

    } 

这工作得很好,但是当我尝试将此邮件发送给其他ActorSystem,我得到的错误巨大的名单: screenshot #1 of the console window with the error

然而,如果我发送一个简单的消息仅由一个整数,一切运作良好。这很可能是序列化问题,但我无法弄清楚它是如何解决的。 我到处搜索过,但还没有找到答案。请你能解释我如何解决这个问题吗?从第一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); 

      } 



     }); 




    } 

} 

}从其他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()); 
     } 
    } 


} 

}

已更新: 下面是错误的开头截图。 screenshot #2 of the console window with the error 它写道System.String []的格式与JSON序列化不兼容。

问题解决了!这个问题关于序列化程序:我使用的是Newtonsoft.Json序列化程序。当涉及到将消息发送到远程ActorSystem时,它无法序列化列表。 Newtonsoft解释说System.String []是不兼容的类型。

解决方案是安装Hyperion串行器: http://getakka.net/docs/Serialization#how-to-setup-wire-as-default-serializer