使用Akka.FSharp在远程参与者之间发送记录时出现SerializationException

r6vfmomb  于 2022-11-05  发布在  其他
关注(0)|答案(1)|浏览(84)

我尝试在Akka.FSharp中的远程参与者之间发送Record消息,但我收到以下序列化异常。

[WARNING][27-11-2021 16:37:25][Thread 0025][akka.tcp://Server@localhost:8001/system/endpointManager/reliableEndpointWriter-akka.tcp%3A%2F%2FClient%40localhost%3A59213-1/endpointWriter/endpointReader-akka.tcp%3A%2F%2FClient%40localhost%3A59213-1] Deserialization failed for message with serializer id [6] and manifest []. Transient association error (association remains live). Failed to deserialize payload object when deserializing ActorSelectionMessage with payload [SerializerId=-5, Manifest=] addressed to [user,serverActor]
Cause: System.Runtime.Serialization.SerializationException: Failed to deserialize payload object when deserializing ActorSelectionMessage with payload [SerializerId=-5, Manifest=] addressed to [user,serverActor]
 ---> System.Runtime.Serialization.SerializationException: Failed to deserialize instance of type . Could not load file or assembly 'Client, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
 ---> System.IO.FileNotFoundException: Could not load file or assembly 'Client, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
File name: 'Client, Culture=neutral, PublicKeyToken=null'
   at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, StackCrawlMarkHandle stackMark, ObjectHandleOnStack assemblyLoadContext, ObjectHandleOnStack type, ObjectHandleOnStack keepalive)
   at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, StackCrawlMark& stackMark, AssemblyLoadContext assemblyLoadContext)
   at System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, StackCrawlMark& stackMark)
   at System.Type.GetType(String typeName, Boolean throwOnError)
   at Hyperion.Extensions.TypeEx.LoadTypeByName(String name, Boolean disallowUnsafeTypes)
   at Hyperion.Extensions.TypeEx.<>c__DisplayClass28_0.<GetTypeFromManifestName>b__0(ByteArrayKey b)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at Hyperion.Extensions.TypeEx.GetTypeFromManifestName(Stream stream, DeserializerSession session)
   at Hyperion.Extensions.TypeEx.GetTypeFromManifestVersion(Stream stream, DeserializerSession session)
   at Hyperion.Serializer.Deserialize[T](Stream stream)
   at Akka.Serialization.HyperionSerializer.FromBinary(Byte[] bytes, Type type)
   --- End of inner exception stack trace ---
   at Akka.Serialization.HyperionSerializer.FromBinary(Byte[] bytes, Type type)
   at Akka.Serialization.Serialization.Deserialize(Byte[] bytes, Int32 serializerId, String manifest)
   at Akka.Remote.Serialization.WrappedPayloadSupport.PayloadFrom(Payload payload)
   at Akka.Remote.Serialization.MessageContainerSerializer.FromBinary(Byte[] bytes, Type type)
   --- End of inner exception stack trace ---
   at Akka.Remote.Serialization.MessageContainerSerializer.FromBinary(Byte[] bytes, Type type)
   at Akka.Serialization.Serialization.Deserialize(Byte[] bytes, Int32 serializerId, String manifest)
   at Akka.Remote.MessageSerializer.Deserialize(ExtendedActorSystem system, Payload messageProtocol)
   at Akka.Remote.DefaultMessageDispatcher.Dispatch(IInternalActorRef recipient, Address recipientAddress, Payload message, IActorRef senderOption)
   at Akka.Remote.EndpointReader.<Reading>b__11_0(InboundPayload inbound)

下面是我为两个远程参与者编写的代码。
伺服器:

open System
open Akka
open Akka.FSharp

type Message = 
    | TestMessage of (int)

[<EntryPoint>]
let main argv =

    let serverConfig() = Configuration.parse("""
    akka {
        actor {
            provider = "Akka.Remote.RemoteActorRefProvider, Akka.Remote"
            serializers {
                json = "Akka.Serialization.HyperionSerializer, Akka.Serialization.Hyperion"
            }
            serialization-bindings {
                "System.Object" = json
            }
        }
        remote {
            helios.tcp {
                port = 8001
                hostname = localhost
            }
        }
    }
    """)

    let serverSystem = serverConfig() |> System.create "Server"

    let serverActor (mailbox: Actor<Message>) = 
        let rec loop() = actor {
            let! message = mailbox.Receive()

            match message with
            | TestMessage(num) ->
                printfn "%d" num
            return! loop()
        }
        loop()

    spawn serverSystem "ServerActor" serverActor |> ignore

    Console.ReadLine() |> ignore

    0 // return an integer exit code

委托单位:

open System
open Akka
open Akka.FSharp

type Message = 
    | TestMessage of (int)

[<EntryPoint>]
let main argv =

    let clientConfig() = Configuration.parse("""
    akka {
        actor {
            provider = "Akka.Remote.RemoteActorRefProvider, Akka.Remote"
            serializers {
                json = "Akka.Serialization.HyperionSerializer, Akka.Serialization.Hyperion"
            }
            serialization-bindings {
                "System.Object" = json
            }
        }
        remote {
            helios.tcp {
                port = 0
                hostname = localhost
            }
        }
    }
    """)

    let clientSystem = clientConfig() |> System.create "Client"
    let serverActorRef = select ("akka.tcp://Server@localhost:8001/user/ServerActor") clientSystem
    serverActorRef <! Message.TestMessage(0)

    Console.ReadLine() |> ignore

    0 // return an integer exit code

我已经配置了Akka.Serialization.Hyperion,但是仍然得到相同的异常。不确定我在这里做错了什么。任何帮助都是appriciate。

xzlaal3s

xzlaal3s1#

您已经在两个地方声明了Message,并且您应该像Bent Tranberg一样使用dot-netty.tcp。下面是一个工作解决方案的截图:

这就是我所做的:

  • 我把TestMessage移到一个公共类库中共享!
  • helios.tcp替换为dot-netty.tcp
  • 已安装最新版本的Akka.Serialization.Hyperion

相关问题