首页 > 解决方案 > 使用协程时警告 Apache Beam

问题描述

我的Kotlin项目正在使用Apache BeamPubsubIO在我尝试实现coroutine之前,一切正常。

这有效:

suspend fun main(args: Array<String>) { ... }

这有效,但会触发警告:

suspend fun main(args: Array<String>) = runBlocking<Unit> { ... }
WARNING: Application name is not set. Call Builder#setApplicationName.
Oct 22, 2021 11:53:52 AM com.google.api.client.googleapis.services.AbstractGoogleClient <init>
WARNING: Application name is not set. Call Builder#setApplicationName.
Oct 22, 2021 11:53:52 AM com.google.api.client.googleapis.services.AbstractGoogleClient <init>
WARNING: Application name is not set. Call Builder#setApplicationName.
Oct 22, 2021 11:53:52 AM com.google.api.client.googleapis.services.AbstractGoogleClient <init>
WARNING: Application name is not set. Call Builder#setApplicationName.
Oct 22, 2021 11:53:53 AM com.google.api.client.googleapis.services.AbstractGoogleClient <init>
WARNING: Application name is not set. Call Builder#setApplicationName.
Oct 22, 2021 11:53:53 AM com.google.api.client.googleapis.services.AbstractGoogleClient <init>
WARNING: Application name is not set. Call Builder#setApplicationName.

警告消息是垃圾邮件(每秒约 5/6 条消息),我找不到摆脱这些的方法。我没有AbstractGoogleClient在我的代码中使用任何相关的东西,所以我真的不知道如何解决这个问题:

@Suppress
suspend fun main(args: Array<String>) = runBlocking<Unit> {
  launch {
    while (true) {
      delay(1000L)
      println("Testing...")
    }
  }

  val options =
      PipelineOptionsFactory.fromArgs(*args).withValidation().`as`(PipelineOptions::class.java)
  val p = Pipeline.create(options)

  p.apply<PCollection<String>>(
        "Read messages from Pub/Sub",
        PubsubIO.readStrings().fromSubscription(options.inputSubscription)
    )
    .apply("Processing", ParDo.of(ProcessData()))

  p.run()
}

任何想法?

标签: kotlinapache-beamgoogle-cloud-pubsub

解决方案


您的问题与这里的Github 问题类似

设置要在每个请求的 UserAgent 标头中使用的应用程序名称,或 null 表示无。

UserAgent 标头示例:

"{application name} Google-API-Java-Client Google-HTTP-Java-Client/1.22.0 (gzip)"

也许这样的事情会解决警告(因为它表明Call Builder#setApplicationName

val service = Builder(...)
       .setHttpRequestInitializer(credentials)
       .setApplicationName("Your app name")
       .build()

推荐阅读