我试图将收到的http请求内容发送到akka节点进行处理。我已经尝试了以下内容类型和akka正确收到消息。但是,当我发送AnyContentAsMultipartFormData
时,akka不会接受它。
我想知道为什么。
以下是我的播放框架收到的http请求日志:
2015-08-29 15:05:08.952 [INFO] [application] in application-akka.actor.default-dispatcher-5
body is AnyContentAsFormUrlEncoded(Map(test -> ArrayBuffer(test)))
2015-08-29 15:06:31.867 [INFO] [application] in application-akka.actor.default-dispatcher-18
body is AnyContentAsText({})
2015-08-29 15:08:23.787 [INFO] [application] in application-akka.actor.default-dispatcher-18
body is AnyContentAsJson({})
2015-08-29 15:09:07.290 [INFO] [application] in application-akka.actor.default-dispatcher-6
body is AnyContentAsMultipartFormData(MultipartFormData(Map(abc -> List(2), test -> List(1)),List(),List(),List()))
akka日志如下:
2015-08-29 15:05:09.146 [INFO] [actors.PlatService] in application-akka.actor.default-dispatcher-2
body is AnyContentAsFormUrlEncoded(Map(test -> ArrayBuffer(test)))
2015-08-29 15:06:31.893 [INFO] [actors.PlatService] in application-akka.actor.default-dispatcher-17
body is AnyContentAsText({})
2015-08-29 15:08:23.935 [INFO] [actors.PlatService] in application-akka.actor.default-dispatcher-18
body is AnyContentAsJson({})
无法接收AnyContentAsMultipartFormData。
我想知道是否有办法解决这个问题?
经过多一点测试后,我遇到了这个例外:
2015-08-30 16:02:01.787 [ERROR] [akka.remote.EndpointWriter] in application-akka.actor.default-dispatcher-5
Transient association error (association remains live)
java.io.NotSerializableException: scala.collection.immutable.MapLike$$anon$2
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1184) ~[na:1.8.0_45]
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548) ~[na:1.8.0_45]
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509) ~[na:1.8.0_45]
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432) ~[na:1.8.0_45]
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178) ~[na:1.8.0_45]
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548) ~[na:1.8.0_45]
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509) ~[na:1.8.0_45]
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432) ~[na:1.8.0_45]
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178) ~[na:1.8.0_45]
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548) ~[na:1.8.0_45]
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509) ~[na:1.8.0_45]
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432) ~[na:1.8.0_45]
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178) ~[na:1.8.0_45]
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348) ~[na:1.8.0_45]
at akka.serialization.JavaSerializer$$anonfun$toBinary$1.apply$mcV$sp(Serializer.scala:234) ~[com.typesafe.akka.akka-actor_2.11-2.4.0-RC1.jar:na]
at akka.serialization.JavaSerializer$$anonfun$toBinary$1.apply(Serializer.scala:234) ~[com.typesafe.akka.akka-actor_2.11-2.4.0-RC1.jar:na]
at akka.serialization.JavaSerializer$$anonfun$toBinary$1.apply(Serializer.scala:234) ~[com.typesafe.akka.akka-actor_2.11-2.4.0-RC1.jar:na]
at scala.util.DynamicVariable.withValue(DynamicVariable.scala:58) ~[org.scala-lang.scala-library-2.11.6.jar:na]
at akka.serialization.JavaSerializer.toBinary(Serializer.scala:234) ~[com.typesafe.akka.akka-actor_2.11-2.4.0-RC1.jar:na]
at akka.remote.serialization.MessageContainerSerializer.serializeSelection(MessageContainerSerializer.scala:45) ~[com.typesafe.akka.akka-remote_2.11-2.4.0-RC1.jar:na]
at akka.remote.serialization.MessageContainerSerializer.toBinary(MessageContainerSerializer.scala:34) ~[com.typesafe.akka.akka-remote_2.11-2.4.0-RC1.jar:na]
at akka.remote.MessageSerializer$.serialize(MessageSerializer.scala:37) ~[com.typesafe.akka.akka-remote_2.11-2.4.0-RC1.jar:na]
at akka.remote.EndpointWriter$$anonfun$serializeMessage$1.apply(Endpoint.scala:837) ~[com.typesafe.akka.akka-remote_2.11-2.4.0-RC1.jar:na]
at akka.remote.EndpointWriter$$anonfun$serializeMessage$1.apply(Endpoint.scala:837) ~[com.typesafe.akka.akka-remote_2.11-2.4.0-RC1.jar:na]
at scala.util.DynamicVariable.withValue(DynamicVariable.scala:58) ~[org.scala-lang.scala-library-2.11.6.jar:na]
at akka.remote.EndpointWriter.serializeMessage(Endpoint.scala:836) ~[com.typesafe.akka.akka-remote_2.11-2.4.0-RC1.jar:na]
at akka.remote.EndpointWriter.writeSend(Endpoint.scala:737) ~[com.typesafe.akka.akka-remote_2.11-2.4.0-RC1.jar:na]
at akka.remote.EndpointWriter$$anonfun$4.applyOrElse(Endpoint.scala:712) ~[com.typesafe.akka.akka-remote_2.11-2.4.0-RC1.jar:na]
at akka.actor.Actor$class.aroundReceive(Actor.scala:480) ~[com.typesafe.akka.akka-actor_2.11-2.4.0-RC1.jar:na]
at akka.remote.EndpointActor.aroundReceive(Endpoint.scala:405) ~[com.typesafe.akka.akka-remote_2.11-2.4.0-RC1.jar:na]
at akka.actor.ActorCell.receiveMessage(ActorCell.scala:525) [com.typesafe.akka.akka-actor_2.11-2.4.0-RC1.jar:na]
at akka.actor.ActorCell.invoke(ActorCell.scala:494) [com.typesafe.akka.akka-actor_2.11-2.4.0-RC1.jar:na]
at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:257) [com.typesafe.akka.akka-actor_2.11-2.4.0-RC1.jar:na]
at akka.dispatch.Mailbox.run(Mailbox.scala:224) [com.typesafe.akka.akka-actor_2.11-2.4.0-RC1.jar:na]
at akka.dispatch.Mailbox.exec(Mailbox.scala:234) [com.typesafe.akka.akka-actor_2.11-2.4.0-RC1.jar:na]
at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) [org.scala-lang.scala-library-2.11.6.jar:na]
at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) [org.scala-lang.scala-library-2.11.6.jar:na]
at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) [org.scala-lang.scala-library-2.11.6.jar:na]
at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107) [org.scala-lang.scala-library-2.11.6.jar:na]
似乎这可能是问题所在。但我不知道如何解决它。
非常感谢任何消息或指示。提前谢谢。
答案 0 :(得分:1)
当您在节点之间发送消息时,它需要被序列化,因为它们不像播放应用程序内部的actor系统那样共享内存。错误消息说的是它出现了一个无法序列化的对象,它甚至足够友好地告诉你它无法序列化的对象,在这种情况下scala.collection.immutable.MapLike$$anon$2
“anon”这个词暗示它是某种东西这是匿名的,如匿名内部类或匿名函数。因此,游戏MultipartFormData
会接受Map
,在这种情况下可能是Map
衣服内部包含的内容。
我会避免在节点之间发送特定于播放的特定类的实例,而是拥有一个包含您自己的模型类和不可变集合对象的自己的消息类的明确协议。这将带来额外的好处,更容易测试并完全消除在akka节点中加载播放类的需要。