You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Logstash GCP PubSub输入插件报NoSuchMethodError错误求助

问题描述

我尝试用基础配置运行Logstash的google_pubsub输入插件,配置如下:

input {
    google_pubsub {
        # Your GCP project id (name)
        project_id => "cosmic-keep-148903"

        # The topic name below is currently hard-coded in the plugin. You
        # must first create this topic by hand and ensure you are exporting
        # logging to this pubsub topic.
        topic => "slm"

        # The subscription name is customizeable. The plugin will attempt to
        # create the subscription (but use the hard-coded topic name above).
        subscription => "slm-sub"

        # If you are running logstash within GCE, it will use
        # Application Default Credentials and use GCE's metadata
        # service to fetch tokens.  However, if you are running logstash
        # outside of GCE, you will need to specify the service account's
        # JSON key file below.
        json_key_file => "/path/to/pkey.json"

        # Should the plugin attempt to create the subscription on startup?
        # This is not recommended for security reasons but may be useful in
        # some cases.
        #create_subscription => false
    }
}
output { stdout { codec => rubydebug } }

运行时出现以下错误:

RUBY.inputworker(/usr/share/logstash/logstash-core/lib/logstash/java_pipeline.rb:410)
RUBY.start_input(/usr/share/logstash/logstash-core/lib/logstash/java_pipeline.rb:401)
org.jruby.RubyProc.call(org/jruby/RubyProc.java:318)
java.lang.Thread.run(java/lang/Thread.java:829)
[ERROR] 2022-08-18 02:38:46.111 [Thread-105] googlepubsub - Expected the service InnerService [FAILED] to be RUNNING, but the service has FAILED
Aug 18, 2022 2:38:46 AM com.google.common.util.concurrent.ListenerCallQueue$PerListenerQueue run
SEVERE: Exception while executing callback: com.google.api.core.AbstractApiService$1@f048817 failed({from = STARTING, cause = java.lang.IllegalStateException: Expected the service InnerService [FAILED] to be RUNNING, but the service has FAILED})
java.lang.IllegalStateException: Expected the service InnerService [FAILED] to be RUNNING, but the service has FAILED
    at com.google.common.util.concurrent.AbstractService.checkCurrentState(AbstractService.java:381)
    at com.google.common.util.concurrent.AbstractService.awaitRunning(AbstractService.java:305)
    at com.google.api.core.AbstractApiService.awaitRunning(AbstractApiService.java:96)
    at com.google.cloud.pubsub.v1.Subscriber.startConnections(Subscriber.java:390)
    at com.google.cloud.pubsub.v1.Subscriber.startStreamingConnections(Subscriber.java:355)
    at com.google.cloud.pubsub.v1.Subscriber.access$200(Subscriber.java:93)
    at com.google.cloud.pubsub.v1.Subscriber$3.run(Subscriber.java:299)
    at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: java.lang.NoSuchMethodError: 'void com.google.common.util.concurrent.Futures.addCallback(com.google.common.util.concurrent.ListenableFuture, com.google.common.util.concurrent.FutureCallback)'
    at com.google.cloud.pubsub.v1.StreamingSubscriberConnection.initialize(StreamingSubscriberConnection.java:218)
    at com.google.cloud.pubsub.v1.StreamingSubscriberConnection.doStart(StreamingSubscriberConnection.java:110)
    at com.google.api.core.AbstractApiService$InnerService.doStart(AbstractApiService.java:148)
    at com.google.common.util.concurrent.AbstractService.startAsync(AbstractService.java:251)
    at com.google.api.core.AbstractApiService.startAsync(AbstractApiService.java:120)
    at com.google.cloud.pubsub.v1.Subscriber.startConnections(Subscriber.java:387)
    ... 4 more

恳请各位提供解决指导。


解决方法

这个错误的核心原因是Guava(Google核心工具库)版本冲突:Logstash内置的Guava版本与google_pubsub插件依赖的Guava版本不兼容,导致找不到指定的Futures.addCallback方法重载。以下是具体解决步骤:

1. 安装兼容版本的google_pubsub插件

不同版本的Logstash对应不同版本的google_pubsub插件,版本不匹配会直接引发依赖冲突:

  • 先查看当前安装的插件版本:
    bin/logstash-plugin list --verbose logstash-input-google_pubsub
    
  • 卸载当前插件:
    bin/logstash-plugin remove logstash-input-google_pubsub
    
  • 安装与你的Logstash版本兼容的插件版本,例如:
    • 若使用Logstash 7.17.x,推荐安装2.1.1版本:
      bin/logstash-plugin install logstash-input-google_pubsub --version 2.1.1
      
    • 若使用Logstash 8.x,可尝试最新兼容版本(如3.0.0及以上)

2. 手动修复Guava依赖冲突(如果步骤1无效)

如果安装指定版本后仍有问题,可以手动对齐Guava版本:

  • 找到Logstash核心的Guava jar包,路径通常为:logstash/logstash-core/lib/jars/guava-<版本号>.jar
  • 找到google_pubsub插件的依赖目录,路径通常为:logstash/vendor/bundle/jruby/2.5.0/gems/logstash-input-google_pubsub-<版本号>/lib/google-cloud-pubsub-v1
  • 将插件目录下的Guava jar包替换为Logstash核心的Guava jar包

3. 验证GCP权限与资源配置

  • 确认你的GCP服务账号(对应json_key_file中的密钥)拥有以下权限:
    • pubsub.subscriptions.consume(消费订阅消息权限)
    • pubsub.subscriptions.get(读取订阅信息权限)
    • 若开启create_subscription => true,还需要pubsub.subscriptions.create权限
  • 确认GCP项目中已存在slm主题,以及slm-sub订阅(若未创建,可手动在GCP控制台创建,或打开配置中的create_subscription => true并确保账号有权限)

内容的提问来源于stack exchange,提问作者llermaly

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.22 01:15:39