2

私はAkka.NETが初めてです。私は最近、大学のプロジェクトを開始し、奇妙な問題に直面しました。2 つの異なるデスクトップ アプリケーションに 2 つの ActorSystems があります。最初の ActorSystem では、Akka.Remote を使用して 2 つのアクター間でメッセージ ZippedAddressListMessage を送信しています。

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

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

    }

これは正常に動作しますが、このメッセージを他の ActorSystem に送信しようとすると、エラーの膨大なリストが表示されます: エラーが 表示されたコンソール ウィンドウのスクリーンショット #1

それでも、1 つの整数のみで構成される単純なメッセージを送信すると、すべてがうまく機能します。シリアル化に問題がある可能性がありますが、どのように解決する必要があるかわかりませんでした。どこでも検索しましたが、まだ答えが見つかりません。この問題を解決する方法を教えてください。

最初の 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://Agent@localhost: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());
        }
    }


}

}

更新: 冒頭のエラーのスクリーンショットを次に示します。 エラーが表示されたコンソール ウィンドウのスクリーンショット #2 System.String[] の形式が JSON シリアル化と互換性がないと書かれています。

4

1 に答える 1