Google PubSub可能存在编码问题

问题描述 投票:0回答:1

从Alpakka PubSub库运行订阅源时,我收到了可能的编码数据。

@Singleton
class Consumer @Inject()(config: Configuration, credentialsService: google.creds.Service)(implicit actorSystem: ActorSystem) {

  implicit val m: ActorMaterializer = ActorMaterializer.create(actorSystem)
  val logger = Logger(this.getClass)
  val subName: String = config.get[String]("google.pubsub.subname")
  val credentials: Credentials = credentialsService.getCredentials
  val pubSubConfig = PubSubConfig(credentials.projectId, credentials.clientEmail, credentials.privateKey)

  val subSource: Source[ReceivedMessage, NotUsed] = GooglePubSub.subscribe(subName, pubSubConfig)
  val ackSink: Sink[AcknowledgeRequest, Future[Done]] = GooglePubSub.acknowledge(subName, pubSubConfig)

  val computeGraph = Flow[ReceivedMessage].map {
    x =>
      logger.info(x.message.data)
      x
  }

  val ackGraph = Flow.fromFunction((msgs: Seq[ReceivedMessage]) => AcknowledgeRequest(msgs.map(_.ackId).toList))

  subSource
    .via(computeGraph)
    .groupedWithin(10, 5.minutes)
    .via(ackGraph)
    .to(ackSink)
    .run()
}

我从PubSub控制台发布消息。我期待我的测试信息出现然而当发布test我收到dGVzdA==。这是预期的结果吗?我在导入私钥时遇到了问题,这可能是它的结果?

消费者热衷于Guice。

scala akka akka-stream google-cloud-pubsub alpakka
1个回答
3
投票

通过REST apis接收的数据将是base64 encoded。我的猜测是,Alpakka Pub / Sub库uses the REST APIs没有正确解码接收到的数据。看起来他们还有一个库,它使用GRPC Pub / Sub客户端作为底层,可能没有这个缺陷?您也可以直接使用Scala的Cloud Pub/Sub Java client library

© www.soinside.com 2019 - 2024. All rights reserved.