1

我正在尝试编写一个程序来侦听另一个程序以 UDP 和 gzips 格式发送假 GELF 消息的特定端口。当 GELF 消息没有被压缩时使用它很容易,但是当它被压缩时我不知道该怎么做。我的代码和错误是:

class ListenUdp(remote: InetSocketAddress) extends ActorPublisher[GelfMessage] with ActorLogging {

  import context.system

  IO(Udp) ! Udp.Bind(self, remote)

  def receive: Receive = {
    case Udp.Bound(local) =>
    log.info(s"############ local: $local")
    context.become(ready(sender()))
  }

  def ready(socket: ActorRef): Receive = {
    case Udp.Received(data, _) =>
      convertToGelf(data.decodeString("UTF-8")) match {
    case Success(message) => onNext(message)
    case Failure(ex0) => ex0.printStackTrace()
  }

  case Udp.Unbind => socket ! Udp.Unbind
  case Udp.Unbound => context.stop(self)

  }
}

com.fasterxml.jackson.core.JsonParseException:非法字符((CTRL-CHAR,代码 31)):标记之间只允许常规空格(\r、\n、\t)��8�TE���� D�xP����ϕ���8�3��nn+����oRֲ+4ĥR�Byn��|>j��c �+4$�9cV���E7v�A������ _@Aq�... (�I0�� ���>�� ; line: 1, column: 2] at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1702) at com.fasterxml.jackson.core.base。 ParserMinimalBase._reportError(ParserMinimalBase.java:558) 在 com.fasterxml.jackson.core.base.ParserMinimalBase._throwInvalidSpace(ParserMinimalBase.java:509) 在 com.fasterxml.jackson.core.json.ReaderBasedJsonParser._skipWSOrEnd(ReaderBasedJsonParser.java: 2364) 在 com.fasterxml.jackson.core.json.ReaderBasedJsonParser.nextToken(ReaderBasedJsonParser.java:644) 在 com。com.fasterxml.jackson.databind.ObjectMapper._readValue(ObjectMapper.java:3756) 上的 fasterxml.jackson.databind.ObjectMapper._initForReading(ObjectMapper.java:3834) com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper. java:2099) 在 play.api.libs.json.jackson.JacksonJson$.parseJsValue(JacksonJson.scala:234) 在 play.api.libs.json.StaticBinding$.parseJsValue(StaticBinding.scala:15) 在 play.api .libs.json.Json$.parse(Json.scala:168) at io.skul.ListenUdp$$anonfun$io$skul$ListenUdp$$convertToGelf$1.apply(ListenUdp.scala:48) at io.skul.ListenUdp $$anonfun$io$skul$ListenUdp$$convertToGelf$1.apply(ListenUdp.scala:46) at scala.util.Try$.apply(Try.scala:192) at io.skul.ListenUdp.io$skul$ListenUdp $$convertToGelf(ListenUdp.scala:46) 在 io.skul.ListenUdp$$anonfun$ready$1。applyOrElse(ListenUdp.scala:36) at akka.actor.Actor$class.aroundReceive(Actor.scala:484) at io.skul.ListenUdp.akka$stream$actor$ActorPublisher$$super$aroundReceive(ListenUdp.scala:22 ) at akka.stream.actor.ActorPublisher$class.aroundReceive(ActorPublisher.scala:325) at io.skul.ListenUdp.aroundReceive(ListenUdp.scala:22) at akka.actor.ActorCell.receiveMessage(ActorCell.scala:526)在 akka.actor.ActorCell.invoke(ActorCell.scala:495) 在 akka.dispatch.Mailbox.processMailbox(Mailbox.scala:257) 在 akka.dispatch.Mailbox.run(Mailbox.scala:224) 在 akka.dispatch。 Mailbox.exec(Mailbox.scala:234) at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) at scala.concurrent .forkjoin.ForkJoinPool。runWorker(ForkJoinPool.java:1979) 在 scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)

我该如何处理?

4

0 回答 0